Answer:
Adapting to different resolutions of the android consists of: Values relative to a LinearLayout
that would be the Pesos ( android:layout_weight
).
Explanation:
You can assign the property android:layout_weight
to its XML elements, which would be like a weight (well say percentage) that is distributed according to the value of this property in all elements that are relative to its LinearLayout
, would be a sum of all Weight
's that are declared in Elementos
within its LinearLayout
which itself has a WeightSum
which is a property that says what is the maximum value ( 100%
) their children. By default the value of WeightSum
is 1
.
The property itself of WeightSum
which is the total weight pattern of LinearLayout
would be android:weightSum=x
where x
would be the weight value (which can be decimal).
The property itself of Layout Weight
which is the weight value of a child element of LinearLayout
would be android:layout_weight=x
where x
would be the value of weight (which can be decimal).
Example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:weightSum="1" <!-- aqui está o weightSum -->
android:orientation="vertical" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/to" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/subject" />
<EditText
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" <!-- aqui está o weight -->
android:gravity="top"
android:hint="@string/message" />
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="@string/send" />
</LinearLayout>
Result:
Observations:
In%%ofthemessageyoudonothavevaluesinEditText
absoluteforheight,youonlyhavedp
thatwouldbetheweightofthatelement.
Ifyoulookatallthechildelementsofandroid:layout_weight="1"
, you will realize that the only element that contains weight would be LinearLayout
of the Message, so the sum of all weight's would be EditText
. But if there were another element with% weight% also, the total weight would be 1
and would exceed the default limit of 1
of 2
that would be WeightSum
.
But if you have LinearLayout
of 1
, for example, you could have WeightSum
child elements containing 10
each, so each element would have 10
of the total size.
Very important remark:
You may be wondering: Okay, but where do I tell if the weight is for height or for width ??
The answer is: This is strictly tied to android:layout_weight=1
of your 10%
that would be this property:
android:orientation="vertical"
From which you can see that it is declared in the% example_configure%, but if it were horizontal the weight's would be applied horizontally only.