Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to save layout_weight in an xml?

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?

like image 781
Alex Styl Avatar asked Oct 26 '12 11:10

Alex Styl


People also ask

What is weight in XML?

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.

What is layout_weight?

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.

What is layout_weight and weightSum in android?

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.

How do you set weight in linear layout?

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" .


1 Answers

Try an integer resource file. It is very similar to dimensions.

http://developer.android.com/guide/topics/resources/more-resources.html

like image 199
Mel Avatar answered Oct 21 '22 05:10

Mel