Android学习笔记-Activity的布局
来源:互联网 发布:新加坡李家王朝 知乎 编辑:程序博客网 时间:2024/05/29 19:01
线性布局
<?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" > <!--android:id 为控件指定的IDandroid:text 制定控件中显示的文字,尽量使用strings.xml中定义的内容android:grivity 指定控件的基本位置,比如居中、居右等位置android:textSize 制定控件中字体的大小android:background 指定该控件所只用的背景颜色,RGB命名法android:width 控件的宽度android:height 控件的高度android:padding*控件的内边距,就是控件当中的内容android:singleLine 如果设置为true则控件的内容在同一行中进行显示android:layout_weight="1" 当前控件占的比重为1 --> <TextView android:id="@+id/first_string" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="#aa0000" android:gravity="center_vertical" android:paddingBottom="40dip" android:paddingLeft="10dip" android:paddingRight="30dip" android:paddingTop="20dip" android:singleLine="true" android:text="@string/hello_world" android:textSize="15pt" /><!-- 上下的layout_weight都为1,每个各占1/2 --> <TextView android:id="@+id/second_string" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="#00aa00" android:gravity="center_vertical" android:paddingBottom="40dip" android:paddingLeft="10dip" android:paddingRight="30dip" android:paddingTop="20dip" android:singleLine="true" android:text="@string/hello_world" android:textSize="15pt" /></LinearLayout>
表格布局
<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="0" ><!-- stretchColumns使用第0列作为拉伸列 --> <TableRow> <TextView android:padding="3dip" android:background="#aa0000" android:text="text11" /> <TextView android:gravity="center_horizontal" android:background="#00aa00" android:padding="3dip" android:text="text12" /> <TextView android:gravity="right" android:background="#0000aa" android:padding="3dip" android:text="text12" /> </TableRow> <TableRow> <TextView android:padding="3dip" android:background="#a00000" android:text="text21" /> <TextView android:gravity="right" android:background="#00a000" android:padding="3dip" android:text="text22" /> </TableRow></TableLayout>
<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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.layout_01.MainActivity" > <!-- <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> --> <!-- android:layout_above 将该控件的底部置于给定ID的控件值上 android:layout_below 将该控件的顶部置于给定ID的控件值下 android:layout_toLeftOf 将该控件的右边缘和给定ID的控件的左边缘对齐 android:layout_toRightOf 将该控件的左边缘和给定ID的控件的右边缘对齐 android:layout_alignBaseline 该控件的baseline和给定ID的空间的baseline对齐 android:layout_alignBottom 该控件的底部边缘与给定ID控件的底部边缘对齐 android:layout_alignLeft 将该控件的左边缘与给定ID控件的左边缘对齐 android:layout_alignRight 将该控件的右边缘与给定ID控件的右边缘对齐 android:layout_alignTop 将给定控件的顶部边缘与给定ID控件的顶部对齐 android:layout_alignParentBottom 如果值为true,则将该控件的底部和父控件的底部对齐 android:layout_alignParentLeft 如果值为true,则将该控件的左边缘与父控件的左边缘对齐 android:layout_alignParentRight 如果值为true,则将该控件的右边缘与父控件的与右边缘对齐 android:layout_alignParentTop 如果值为true,则将控件的顶部与父控件的顶部对齐 android:layout_centerHorizonal 如果值为true,该控件将被置于水平方向的中央 android:layout_centerInParent 如果值为true,该控件将被置于父控件水平方向和垂直方向中央 android:layout_centerVertical 如果值为true,该控件将被置于垂直方向的中央 --> <TextView android:id="@+id/label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Type here:"/> <EditText android:id="@+id/entry" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@android:drawable/editbox_dropdown_light_frame" android:layout_below="@id/label"/> <Button android:id="@+id/ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/entry" android:layout_alignParentRight="true" android:layout_marginLeft="10px" android:text="OK"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/ok" android:layout_alignTop="@id/ok" android:text="Cancel"/></RelativeLayout>
本文出自 “优赛工作室” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/1577500
0 0
- Android学习笔记-Activity的布局
- Android开发学习笔记-6 Activity-5 Activity的布局
- Android学习笔记5——Activity的布局初步
- Android学习笔记:<三>Activity布局初步
- Android学习笔记3:Activity布局
- Android的布局学习笔记
- Android学习笔记-Android非布局activity中布局文件及控件加载方法
- 4.Android学习笔记-android的布局
- Android学习笔记----Activity
- android学习Activity笔记
- Android学习笔记-Activity
- Android 学习笔记--Activity
- Android布局学习笔记
- Android 布局学习笔记
- Android学习笔记--布局
- android学习笔记-布局
- Android 学习笔记-布局
- Android学习笔记--Activity的生命周期
- iOS获取路由器地址类似于192.168.1.1
- Android学习笔记-Activity&Intent
- Android学习笔记-EditText&TextView&Button&菜单栏
- 笔试题目记录
- Android学习笔记-Activity的生命周期
- Android学习笔记-Activity的布局
- Android学习笔记-常用控件
- Android学习笔记-Handler的使用
- Android学习笔记-SQLite的使用
- Spring4学习笔记-SpringJDBC基本操作(补充)
- Android学习笔记-文件下载
- Android学习笔记-广播机制
- Android学习笔记-ContentProvider
- Android学习笔记-XML处理