参见:API | Developer | Common LayoutObjects
较好的学习和参考方法:参见API 中的 simple
设置背景:为图形(图形:图片 + 颜色 + 动画 + 状态列表)
xxx.xml :android:background="图形"
padding :内间距(单位:px)
@android:drawable/editbox_background :引用android系统的 R 文件 常量资源
相对布局:RelativeLayout
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
android:id=“@+id/button" :表示向 R 文件中添加一个ID
android:layout_below="@id/button" :表示此控件放置于 引用为ID 的控件的地下
android:layout_toLeftof=“@id/button” :表示此控件放置于 应用为ID 的控件的左边
android:layout_toRightOf="@id/button":表示此控件放置于 应用为ID 的控件的右边
android:layout_alignTop="@id/textview" <!--与指定ID的控件顶部对齐-->
android:layout_marginLeft="5dp" <!--控件左边间距为5像素-->
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
表格布局:tableLayout
<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" <!--xmlns : xml namespace--> android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1"> <TableRow> <!---当中的一个控件就是一列--> <TextView android:text="@string/table_layout_4_open" android:padding="3dip" /> <TextView android:text="@string/table_layout_4_open_shortcut" android:gravity="right" android:padding="3dip" /> </TableRow> <TableRow> <!---当中的一个控件就是一列--> <TextView android:text="@string/table_layout_4_save" android:padding="3dip" /> <TextView android:text="@string/table_layout_4_save_shortcut" android:gravity="right" android:padding="3dip" /> </TableRow> </TableLayout>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
帧布局 : FrameLayout (与 gif 动画类似)
资源文件:
1.desktop.jpg
2.hand.jpg
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/desktop"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/hand"/>
</FrameLayout>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
效果图:
此外还有:absoluteLayout在此处不做介绍!