1:LinearLayout


直接上代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.yunlibeauty.test.MainActivity"
    android:orientation="vertical"
    android:id="@+id/base_layout">
<LinearLayout  
	android:id="@+id/layout1"        
	android:layout_width="match_parent"
        android:layout_height="0dp"       
	android:background="@color/colorAccent"        
	android:layout_weight="1"        
	android:orientation="horizontal" />    
   <LinearLayout        
	android:id="@+id/layout2"        
	android:layout_width="match_parent"
        android:layout_height="0dp"        
	android:background="@color/colorPrimaryDark"        
	android:layout_weight="1"       
	android:orientation="horizontal">  
      
	<LinearLayout           
		android:id="@+id/layout2_1"            
		android:layout_width="0dp"           
		android:layout_height="match_parent"
           	android:layout_weight="1"            
		android:background="@color/colorC"            
		tools:ignore="Suspicious0dp" />        
	<LinearLayout            
		android:id="@+id/layout2_2"            
		android:layout_width="0dp"            
		android:layout_height="match_parent"
                android:layout_weight="1"            
		android:background="@color/colorB"            
		tools:ignore="Suspicious0dp" />    
	</LinearLayout>    
	<LinearLayout        
		android:id="@+id/layout3"        
		android:layout_width="match_parent"        
		android:layout_height="0dp"        
		android:layout_weight="1"        
		android:background="@color/colorPrimary" >            
	</LinearLayout>   
</LinearLayout>
 
 
我这里首先把屏幕垂直分成了三分, layout1、layout2、layout3. 在layout2里我又水平分成两份 layout2_1及layout2_2

结合代码LinearLayout常用属性:
1:id作为layout的标识
2:orientation布局的方向,是垂直布局还是线性布局,比如最外层id为base_layout的我设为了垂直,先垂直分成的三分。而在layout2里我设置了水平布局,所以水平分成了两份
3:layout_width、layout_height,指定的是布局的宽高,一般不直接去写数字,会设为
fill_parent\match_parent(这里我用了或,因为他们两是一样的,Android2.2以后是一样的,2.2之前没有match_parent)、wrap_content组件的实际大小

4:layout_weight 占的权重,比如我都设为了1,如果我将id为layout1的设为2,那layout1将会占用屏幕的一半。
5:backgroud:背景,可以设置为颜色或者图片

 
 
 
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值