Multiple LinearLayout nested layout instances in Android app _android

Source: Internet
Author: User

In the android  UI layout, using LinearLayout nesting, found that the effect is not as I expected
to check the data, said to set the Layout_weight properties
information is not very clear, and did not look carefully, to get, The result becomes more and more confusing. The
then settle down and write your own XML test and find out the following.
If LinearLayout is the outermost layer, it will not eject the Layout_weight attribute,
in other words the outermost level cannot be layout_weight
XML layout is as follows

 <linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android" Android : layout_width= "fill_parent" android:layout_height= "fill_parent" > <linearlayout android:layout_width= "fill_p" Arent "android:layout_height=" wrap_content "android:orientation=" vertical "> <textview Android:layout_widt H= "Fill_parent" android:layout_height= "wrap_content" android:text= "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz" Android:textSiz E= "18SP" android:layout_marginleft= "5px" android:layout_marginbottom= "10px" android:textcolor= "@android: Color/dar Ker_gray "/> <textview android:layout_width= fill_parent" android:layout_height= "Wrap_content" Android : text= "xxxxxxxxxxxxxxxxxxxxxxx" android:layout_marginleft= "50px" android:layout_marginbottom= "10px" Android:text Size= "18sp"/> </LinearLayout> </LinearLayout> 

This can be shown normally, but when we set the nesting linearlayout direction to horizontal, the first TextView fills the entire linearlayout, and the second TextView control is not displayed.
When we add the android:layout_weight= "1" attribute to the two TextView, we can show that the effect I do not say, we all understand.
Find an interesting phenomenon: we delete the android:layout_weight= "1" of the two controls, and delete the nested linearlayout directional attributes, and the code is the same as the first
Note that we said earlier that the XML is displayed correctly, and now the exact same XML code shows the error.
When we set the android:layout_weight= "1" property of only one control, we find that there is also a display error
PS: I just looked at it with a visual tool, didn't compile it, said it, just told you not to be misled by its visual effects (visual is the cause of the tool). As for how the compiler will show, this interested can go to see. I said that the error is not to say that the file has errors, just say not to achieve the effect I want (are shown).


Further, look at such an effect:

The code is as follows:

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Fill_parent" android:layout_height= "fill_parent" android:orientation= "vertical" > <view android:layout_width= "fill_parent" "Android:layout_height=" 2dip "android:background=" #E4E4E4 "/> <linearlayout android:layout_width=" Fill_pare NT "android:layout_height=" wrap_content "android:orientation=" horizontal "> <linearlayout android:layout_w

   Idth= "0DP" android:layout_height= "Wrap_content" android:layout_weight= "1" android:orientation= "vertical" > <imageview android:layout_width= "80dip" android:layout_height= "80dip" android:layout_gravity= "Center_horiz Ontal "android:layout_margintop=" 10dip "android:src=" @drawable/icon_main_sugar "/> <textview Android : layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_gravity= "Center_horizontal" a ndroid:paddingtop= "3dip" Android: text= "Water" android:textcolor= "#7C8187" android:textsize= "15dip"/> </LinearLayout> <view Androi
   D:layout_width= "2dip" android:layout_height= "match_parent" android:background= "#E4E4E4"/> <linearlayout Android:layout_width= "0DP" android:layout_height= "Wrap_content" android:layout_weight= "1" android:orientation= "V Ertical "> <imageview android:layout_width=" 80dip "android:layout_height=" 80dip "Android:layout_grav Ity= "Center_horizontal" android:layout_margintop= "10dip" android:src= "@drawable/icon_main_eat"/> <TextV Iew android:layout_width= "wrap_content" android:layout_height= wrap_content "android:layout_gravity=" Center_ho  Rizontal "android:paddingtop=" "3dip" android:text= "tableware" android:textcolor= "#7C8187" android:textsize= "15dip" /> </LinearLayout> <view android:layout_width= "2dip" android:layout_height= "Match_parent" Andro Id:background= "#E4E4E4"/> <linearlayout android:layout_width= "0DP" android:layout_height= "Wrap_content" android:layout_weight= " 1 "android:orientation=" vertical "> <imageview android:layout_width=" 80dip "android:layout_height=" 80 Dip "android:layout_gravity=" center_horizontal "android:layout_margintop=" 10dip "android:src=" @drawable/icon_m Ain_info "/> <textview android:layout_width= wrap_content" android:layout_height= "Wrap_content" Andr 
    Oid:layout_gravity= "Center_horizontal" android:paddingtop= "3dip" android:text= "Information" android:textcolor= "#7C8187" Android:textsize= "15dip"/> </LinearLayout> </LinearLayout> <view android:layout_width= "fill _parent "android:layout_height=" 2dip "android:background=" #E4E4E4 "/> <linearlayout android:layout_width=" fi Ll_parent "android:layout_height=" wrap_content "android:orientation=" horizontal "> <linearlayout android:l Ayout_width= "Wrap_contenT "android:layout_height=" Wrap_content "android:layout_weight=" 1 "android:orientation=" vertical "> <Ima
    Geview android:layout_width= "80dip" android:layout_height= "80dip" android:layout_gravity= "Center_horizontal" android:layout_margintop= "10dip" android:src= "@drawable/evaluate_self"/> <textview android:layout_wi Dth= "Wrap_content" android:layout_height= "wrap_content" android:layout_gravity= "Center_horizontal" Android:pad dingtop= "3dip" android:text= "Sugar" android:textcolor= "#7C8187" android:textsize= "15dip"/> </linearlayou t> <view android:layout_width= "2dip" android:layout_height= "match_parent" android:background= "#E4E4E4" > <linearlayout android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layout_ weight= "1" android:orientation= "vertical" > <imageview android:layout_width= "80dip" android:layout_he Ight= "80dip" Android: layout_gravity= "Center_horizontal" android:layout_margintop= "10dip" android:src= "@drawable/target_manager"/> <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layout_grav Ity= "Center_horizontal" android:paddingtop= "3dip" android:text= "Sugar" android:textcolor= "#7C8187" Android:te Xtsize= "15dip"/> </LinearLayout> <view android:layout_width= "2dip" android:layout_height= "Match_pa" Rent "android:background=" "#E4E4E4"/> <linearlayout android:layout_width= "Wrap_content" Android:layout_h eight= "Wrap_content" android:layout_weight= "1" android:orientation= "vertical" > <imageview android:lay Out_width= "80dip" android:layout_height= "80dip" android:layout_gravity= "Center_horizontal" Android:layout_marg
    intop= "10dip" android:src= "@drawable/drug_manager"/> <textview android:layout_width= "Wrap_content" Android:layout_height= "WRAp_content "android:layout_gravity=" Center_horizontal "android:paddingtop=" 3dip "android:text=" Sugar "Android : textcolor= "#7C8187" android:textsize= "15dip"/> </LinearLayout> </LinearLayout> <view Androi D:layout_width= "Fill_parent" android:layout_height= "2dip" android:background= "#E4E4E4"/> <linearlayout Oid:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:orientation= "Horizontal" > <Line Arlayout android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:layout_weight= "1" an
    droid:orientation= "vertical" > <imageview android:layout_width= "80dip" android:layout_height= "80dip" Android:layout_gravity= "Center_horizontal" android:layout_margintop= "10dip" android:src= "@drawable/news_share"/&

   Gt <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Center_horizontal"Android:paddingtop=" 3dip "android:text=" android:textcolor= "#7C8187" android:textsize= "15dip"/> </LinearLayout> <view android:layout_width= "2dip" android:layout_height= "Match_parent" android:backg
   round= "#E4E4E4"/> <linearlayout android:layout_width= "wrap_content" android:layout_height= "Wrap_content"
    android:layout_weight= "1" android:orientation= "vertical" > <imageview android:layout_width= "80dip" android:layout_height= "80dip" android:layout_gravity= "Center_horizontal" android:layout_margintop= "10dip" Andr oid:src= "@drawable/set_manager"/> <textview android:layout_width= "Wrap_content" Wrap_content "android:layout_gravity=" Center_horizontal "android:paddingtop=" 3dip "android:text=" Settings "Andro Id:textcolor= "#7C8187" android:textsize= "15dip"/> </LinearLayout> <view android:layout_width= "2di P "Android:layout_height= "Match_parent" android:background= "#E4E4E4"/> <linearlayout android:layout_width= "Wrap_content" and
    roid:layout_height= "Wrap_content" android:layout_weight= "1" android:orientation= "vertical" > <imageview Android:layout_width= "80dip" android:layout_height= "80dip" android:layout_gravity= "Center_horizontal" Androi d:layout_margintop= "10dip" android:src= "@drawable/content_report"/> <textview android:layout_width= "Wra P_content "android:layout_height=" wrap_content "android:layout_gravity=" Center_horizontal "android:paddingTop=" "3dip" android:text= "task" android:textcolor= "#7C8187" android:textsize= "15dip"/> </LinearLayout> & lt;/linearlayout> <view android:layout_width= "fill_parent" android:layout_height= "2dip" android:background= "
 #E4E4E4 "/> </LinearLayout>

Related Article

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.