火秀刷枪精灵,拼塔安的老公,编织毛衣花样
本文实例讲述了android编程之线性布局linearlayout用法。分享给大家供大家参考,具体如下:
线性布局(linearlayout)
可以让它的子元素垂直或水平的方式排成一行(不设置方向的时候默认按照垂直方向排列)。
下面示例是在别人基础上修改的main.xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <linearlayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:baselinealigned="false" android:layout_weight="1" > <linearlayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"> <textview android:text="@string/color_green" android:textcolor="#ff0000" android:background="#00aa00" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"/> <textview android:text="@string/color_blue" android:background="#0000aa" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"/> </linearlayout> <linearlayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1"> <textview android:text="@string/color_black" android:background="#000000" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/> <textview android:text="@string/color_yellow" android:background="#aaaa00" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/> <textview android:text="@string/color_unknown" android:background="#00aaaa" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/> </linearlayout> </linearlayout> <linearlayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2"> <textview android:text="@string/color_red" android:gravity="fill_vertical" android:background="#aa0000" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2"/> <textview android:text="@string/color_white" android:textcolor="#ff0000" android:background="#ffffff" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2"/> </linearlayout> </linearlayout>
string.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">hello world, testabsolutelayoutactivity!</string> <string name="app_name">testabsolutelayout</string> <string name= "color_red">red</string> <string name= "color_green">green</string> <string name= "color_blue">blue</string> <string name= "color_white">white</string> <string name= "color_black">black</string> <string name= "color_yellow">yellow</string> <string name= "color_unknown">unknown</string> </resources>
效果图如下:
常用的属性:
android:orientation:可以设置布局的方向
android:gravity:用来控制组件的对齐方式
layout_weight:控制各个组件在布局中的相对大小
更多关于android编程布局相关内容可查看本站专题:《android布局layout技巧总结》
希望本文所述对大家android程序设计有所帮助。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Android studio开发小型对话机器人app(实例代码)
Android通过Java sdk的方式接入OpenCv的方法
Android 通过cmake的方式接入opencv的方法步骤
Android Studio finish()方法的使用与解决app点击“返回”(直接退出)
Android 进度条 ProgressBar的实现代码(隐藏、出现、加载进度)
网友评论