I need to change the layout_weight of 3 views in a layout, according to the physical size of the screen. The views have the weight of 0-1-0, but this has to change to 0.2-0.6-0.2 when the layout is used in an xlarge screen.
I tried saving the layout_weight inside different copies of the dimensions.xml (one in values/dimensions and an other one in values-xlarge/dimensions), but it looks like I cannot give a dimension without setting dp/px or w/e (cannot save a "raw" number like 1, or 0.2).
Is it possible to do via xml somehow, or do I have to work programmatically in order to achieve that?
Android Layouts View Weight Weight defines how much space a view will consume compared to other views within a LinearLayout. Weight is used when you want to give specific screen space to one component compared to other.
LinearLayout also supports assigning a weight to individual children with the android:layout_weight attribute. This attribute assigns an "importance" value to a view in terms of how much space it should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view.
android:weightSum. Defines the maximum weight sum. If unspecified, the sum is computed by adding the layout_weight of all of the children. This can be used for instance to give a single child 50% of the total available space by giving it a layout_weight of 0.5 and setting the weightSum to 1.0.
Layout Weight To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .
Try an integer resource file. It is very similar to dimensions.
http://developer.android.com/guide/topics/resources/more-resources.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With