I believe that in the beginning of the study of Android programming, you will be a little confused "match_parent" and "fill_parent" the ratio between the problem; Here is an example of the people understand!
Compile the following code:
1<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"2Xmlns:tools= "Http://schemas.android.com/tools"3Android:id= "@+id/line"4Android:layout_width= "Match_parent"5android:layout_height= "Match_parent"6android:orientation= "Horizontal"7>8<LinearLayout9Android:layout_width= "Fill_parent"Tenandroid:layout_height= "Fill_parent" OneAndroid:background= "#00ff00" Aandroid:layout_weight= "1"/> - - the<LinearLayout -Android:layout_width= "Fill_parent" -android:layout_height= "Fill_parent" -Android:background= "#ff0000" +android:layout_weight= "2"/> - +<LinearLayout AAndroid:layout_width= "Fill_parent" atandroid:layout_height= "Fill_parent" -Android:background= "#0000ff" -android:layout_weight= "3"/> - -</LinearLayout>
The results of the operation are as follows:
This time will have doubts, how can this, this ratio is 2:1, then three to where? The code inside clearly has three Ah, also set 3, and 1 and 2 of the proportion is not right, 1:2:3 turned 2:1:0, how can this? A: Here is actually not so simple, or we need to calculate, the online algorithm has several, here gives the author feel more easy to understand a kind: Step 1: All are fill_parent, but the screen only one, then 1-3 = 2 fill_parent Step 2: The ratio is 1/6,2/6,3/6 Step 3: First come first served first, calculated: 1-2 * (1/6) = 2/3 fill_parent then to the second, calculated: 1-2 * (2/6) = 1/3 Fill_parent last to Thre E, Calculate 1-2 * (3/6) = 0 fill_parent Step 4: So the final result is: One accounted for two, two accounted for, three what all wood has above is why the three did not appear the reason.
Android Program Fill_parent Scale detailed: