Android Program Fill_parent Scale detailed:

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.