2-23安卓自学

  今天继续学习Linerlayout,发现Linerlayout可以实现嵌套,即大的布局可以是Linerlayout,然后在大的布局里面还可以嵌套小的Linerlayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
    xmlns:tools="http://schemas.android.com/tools"    
    android:id="@+id/LinearLayout1"    
    android:layout_width="match_parent"    
    android:layout_height="match_parent"    
    android:orientation="horizontal">   
        
    <LinearLayout    
        android:layout_width="0dp"    
        android:layout_height="fill_parent"    
        android:background="#ADFF2F"     
        android:layout_weight="1"/>    
       
        
    <LinearLayout    
        android:layout_width="0dp"    
        android:layout_height="fill_parent"    
        android:background="#DA70D6"     
        android:layout_weight="2"/>    
        
</LinearLayout>
但是如果这样写必须有要求,就是一个父Linerlayout如果包含多个字Linerlayout,就要在父Linerlayout声明orientation="horizontal",有两个选项,水平和数竖直,即布局样式

weight属性详解:

当然,如果我们不适用上述那种设置为0dp的方式,直接用wrap_content和match_parent的话, 则要接着解析weight属性了,分为两种情况,wrap_content与match_parent!另外还要看 LinearLayout的orientation是水平还是竖直,这个决定哪个方向等比例划分

这个可以实现更简单的布局划分,按照比例进行分配。

 
posted @ 2021-02-23 22:01  软工新人  阅读(28)  评论(0编辑  收藏  举报