Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing layout_weight reference from dimensions (dimens)

I need to set different layout weights for different screen size devices and I want to pass the values from the dimens file, the problem is that the reference from the dimens file keeps throwing errors

error: Error: Integer types not allowed (at 'progress_widget_item3_weight' with value '9'). 

or

error: Error: Float types not allowed (at 'progress_widget_item3_weight' with value '9.1'). 

<dimen name="progress_widget_item3_weight">9</dimen> 

How do I pass the value from the dimens file for the layout_weight ? Thank you

like image 569
androidu Avatar asked Feb 27 '12 08:02

androidu


1 Answers

Instead of dimensions you can use integer to declare and reference integers.

Example declaration in integers.xml:

<resources>     <integer name="left">1</integer>     <integer name="right">2</integer> </resources> 

Example reference in layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical" >      <FrameLayout         android:layout_width="0dp"         android:layout_height="fill_parent"         android:layout_weight="@integer/left" />      <FrameLayout         android:layout_width="0dp"         android:layout_height="fill_parent"         android:layout_weight="@integer/right" />  </LinearLayout> 
like image 103
AZ13 Avatar answered Oct 11 '22 03:10

AZ13