Android布局管理器

Android布局管理器()

1、TableLayout(采用表格的形式对控件的布局进行管理)。

2、FramLayout(框架布局管理器)。

3、LinearLayout(线性布局管理器)。

一、对相关布局管理器的解释

1、TableLayout(表格布局)。

<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" >
	<TableRow>		//表中的一行
    	<EditText	      //文本编辑框
    	    android:id="@+id/edit" //设置ID
       	 	android:layout_width="wrap_content" //宽度为文字宽度
        	android:layout_height="wrap_content"//高度为文字高度
        	android:text="@string/hello_world" />//引用string.xml文件中的文字信息
    	<Button  //设置的按钮
    	    android:id="@+id/button"
    	    android:layout_width="wrap_content"
        	android:layout_height="wrap_content"
			android:text="@string/txt1"
    	    />
	</TableRow>
	<View 
	    android:layout_height="2px"
	    android:background="#F75000"
	    />
	<View 
	    android:layout_height="2px"
	    android:background="#F75000"
	    />
	<TableRow >
	    <TextView
	        android:id="@+id/text1"
	        android:layout_width="wrap_content"
	        android:layout_height="wrap_content"
	        android:textSize="45px"//设置文字大小
	        android:text="@string/txt2"
	        />
	    <RadioGroup //单选钮
	        android:id="@+id/text2"
	        android:layout_width="wrap_content"
	        android:layout_height="wrap_content"
	        android:orientation="horizontal"
	        android:checkedButton="@+id/RBut1"//设置默认选中项
	        >
	        <RadioButton  //单选项
	            android:id="@+id/RBut1"
	            android:text="@string/txt3"
	            />
	        <RadioButton //单选项
	           android:id="@+id/RBut2"
	           android:text="@string/txt4"
	            />
	       </RadioGroup>
 	</TableRow>
</TableLayout> 
<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:shrinkColumns="3"//设置第三列为可伸缩列也就是说当文字过长时会对文字进行换行
    android:collapseColumns="0,3"//设置第1列与第四列隐藏
    android:background="@drawable/dd"//设置背景图片
    tools:context="${relativePackage}.${activityClass}"
    
     >
<TableRow>    		 <span style="white-space:pre">			</span>//第一行
<TextView 
<span style="white-space:pre"></span><pre name="code" class="java">  android:layout_column = "1"<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;">				</span>//<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;">表示列标,不可改变</span>
android:text="@string/txt1"  android:gravity="center_horizontal"//定义控件水平居中  android:padding="10px"      />    <TextView        android:layout_column = "1"// 表示列标,不可改变 android:text="@string/txt2"  android:gravity="center_horizontal" android:padding="10px" /> <TextView   android:layout_column = "2" 表示列标,不可改变 android:text="@string/txt3" android:gravity="center_horizontal" android:padding="10px" <TextView  android:layout_column = "3"// 表示列标,不可改变 android:text="@string/txt4" android:gravity="center_horizontal" android:padding="10px" </TableRow> <View   android:layout_height="3px" android:background="#AE0000" /> <TableRow> <TextView  android:layout_column = "0" android:text="@string/txt5" android:gravity="center_horizontal" android:padding="10px" /> <TextView  android:layout_column = "1" android:text="@string/txt6" android:gravity="center_horizontal" android:padding="10px" /> <TextView  android:layout_column = "2" android:text="@string/txt7" android:gravity="center_horizontal" android:padding="10px" /> <TextView  android:layout_column = "3" android:text="@string/txt8" android:gravity="center_horizontal" android:padding="10px" /> </TableRow></TableLayout>
 

注:做软件开发最常用的就是表格布局以及线性布局。

2、相对布局(RelativeLayout)

相对布局的意思就是相对一个参考点就是某一个控件进行操作。

<span style="font-family:Microsoft YaHei;"><RelativeLayout   //
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" >

    <ImageView  //图片控件
        android:id="@+id/image1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/aa"//取得照片
        />
    <ImageView 
        android:id="@+id/image2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/dd"
        android:layout_toRightOf="@+id/image1"//image2相对于image1,在image1的右边
        />
    <ImageView 
        android:id="@+id/image3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/tt"
        android:layout_toRightOf="@+id/image1"//image3相对于image1在其右边
        android:layout_below="@+id/image2"//image3相对于image2在其下边
        />
 </RelativeLayout></span>

3、FrameLayout(框架布局管理器)

这种布局管理器的效果是所有添加的组件会叠加在一起。

4、 多种布局的嵌套

 <LinearLayout<span style="white-space:pre">					 //总体上是线性布局
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"                                //垂直排列
    tools:context="${relativePackage}.${activityClass}" >
	<RelativeLayout                                          //嵌套相对布局管理器
    	android:layout_width="fill_parent"
    	android:layout_height="wrap_content" //这里一定要写成这种形式,这是为了防止当前布局管理器占据全屏的高度,使后边所定义的布局管理器无法正常显示 
    	android:orientation="vertical"
    	 >
	    <ImageView 
	        android:id="@+id/image1"
	        android:layout_width="wrap_content"
    		android:layout_height="wrap_content"
    		android:src="@drawable/aa"
	        />
	      <ImageView 
	        android:id="@+id/image2"
	        android:layout_width="wrap_content"
    		android:layout_height="wrap_content"
    		android:src="@drawable/tt"
    		android:layout_toRightOf="@+id/image1"
	        />
	       <ImageView 
	        android:id="@+id/image3"
	        android:layout_width="wrap_content"
    		android:layout_height="wrap_content"
    		android:src="@drawable/dd"
    		android:layout_below="@+id/image2"
    		android:layout_toRightOf="@+id/image1"
	        />
	    </RelativeLayout> 
	   
	    <TableLayout  //嵌套表格布局管理器
	        android:orientation="horizontal"//排列方式为水平
	        android:layout_width="wrap_content"
                android:layout_height="wrap_content"
 	        >
	       <TableRow>
	        <TextView
	            android:layout_width="wrap_content"
	            android:layout_height="wrap_content"
	            android:textSize="45px"
	            android:text="@string/text1"
	            />
	        <RadioGroup
	            android:id="@+id/radio1" 
	            android:layout_width="wrap_content"
	            android:layout_height="wrap_content"
	            android:orientation="vertical"
	            android:checkedButton="@+id/Rbut1"
	            >
	            <RadioButton 
	               android:id="@+id/Rbut1"
	               android:layout_width="wrap_content"
	               android:layout_height="wrap_content"
	               android:text="@string/text2"
	                />
	            <RadioButton 
	               android:id="@+id/Rbut2"
		       android:layout_width="wrap_content"
	               android:layout_height="wrap_content"
	               android:text="@string/text3"
	                />
	        </RadioGroup>
	        </TableRow>
	        <View 
	            android:layout_height="3px"
	            android:background="#FF0000"
	            />
	    </TableLayout>
</LinearLayout> 






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

龙潭一条鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值