[Android] 006_Activity控件布局_LinearLayout

Android_006_Activity控件布局_LinearLayout

LinearLayout: 线型布局, 分为”水平线型布局” 和 “垂直线型布局”, 只需要修改main.xml文件就可以对布局进行设置, 新建一个Activity, 那么他的默认布局方式就是线性布局.

在main.xml文件中, 将<LinearLayout></LinearLayout>设置为根标签, 那么在这个标签里的控件就会以线性布局来摆放.

LinearLayout 的属性android:orientation 可以用来控制是 “水平线形布局”还是”垂直线形布局”.

android:orientation=”vertical” 代表”垂直”线形布局

android:orientation=”horizontal” 代表 “水平” 线形布局

1. 垂直线性布局, 所有的控件从上到下依次摆放.

main.xml中的代码:

<? xml version="1.0" encoding="utf-8" ?>

< LinearLayout xmlns:android ="http://schemas.android.com/apk/res/android"

android:orientation
="vertical"

android:layout_width
="fill_parent"

android:layout_height
="fill_parent"

>

< TextView

android:id ="@+id/TextView1"

android:layout_width
="fill_parent"

android:layout_height
="wrap_content"

android:text
="@string/TextView1"

android:textColor
="#ff0000"

/>

< Button

android:id ="@+id/Button1"

android:layout_width
="fill_parent"

android:layout_height
="wrap_content"

android:text
="@string/Button1"

android:textColor
="#00ff00"

/>

< TextView

android:id ="@+id/TextView1"

android:layout_width
="fill_parent"

android:layout_height
="wrap_content"

android:text
="@string/TextView1"

android:textColor
="#ffffff"

/>

< Button

android:id ="@+id/Button1"

android:layout_width
="fill_parent"

android:layout_height
="wrap_content"

android:text
="@string/Button1"

android:textColor
="#ffff00"

/>

</ LinearLayout >

运行后显示的结果如下图, 所有的控件从上到下顺序摆放.

clip_image002

2. 水平线性布局, 所有的控件从左到右依次摆放.

main.xml中文件的代码:

<? xml version="1.0" encoding="utf-8" ?>

< LinearLayout xmlns:android ="http://schemas.android.com/apk/res/android"

android:orientation
="horizontal"

android:layout_width
="fill_parent"

android:layout_height
="fill_parent"

>

< TextView

android:id ="@+id/TextView1"

android:layout_width
="wrap_content"

android:layout_height
="fill_parent"

android:text
="@string/TextView1"

android:textColor
="#ff0000"

/>

< Button

android:id ="@+id/Button1"

android:layout_width
="wrap_content"

android:layout_height
="fill_parent"

android:text
="@string/Button1"

android:textColor
="#0000ff"

/>

< TextView

android:id ="@+id/TextView2"

android:layout_width
="wrap_content"

android:layout_height
="fill_parent"

android:text
="@string/TextView2"

android:textColor
="#00ff00"

/>

< Button

android:id ="@+id/Button2"

android:layout_width
="wrap_content"

android:layout_height
="fill_parent"

android:text
="@string/Button2"

android:textColor
="#0000ff"

/>

</ LinearLayout >

运行后显示后的结果下图, 所有控件从左到右依次摆放

clip_image003

仔细对比两个文件的不同之处…

转载于:https://www.cnblogs.com/shanhaiyang/archive/2011/07/10/2102579.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值