10.LinearLayout学习

1.以行为布局,下面是基本使用

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >

orientation :水平或垂直。

fill_parent:填充尽可能多的空间

wrap_content:根据内容来控制大小

2.布局内控件

2.1 android:gravity 设置对其方式。

android:gravity="right"

2.2 android:layout_weight 设置高度

默认为0,就是需要多少显示多少。

1,显示整个,

2,显示1/2 ...

3.继承关系

java.lang.Object        android.view.View              android.view.ViewGroup                    android.widget.LinearLayout

所以它也是一个View,可以进行一些View的操作。

11.AbsoluteLayout和FrameLayout

1.AbsoluteLayout 要指定精确坐标的一种布

绝对布局。不推荐使用。

<?xml version = "1.0" encoding = "utf-8"?><AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:padding="10dip">  <TextView android:id="@+id/lable"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:text="请输入用户名:"/>  <EditText android:id="@+id/text"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:layout_x="100dip"            android:layout_y="20dip"/>  <Button android:id="@+id/cancel"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_x="10dip"          android:layout_y="50dip"          android:text="取消"/></AbsoluteLayout>

2.FrameLayout 框架布局

以层叠的方式展示。

它的大小是最大子控件的大小。

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">     <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff000000" android:gravity="center" android:text="1"/>     <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff654321" android:gravity="center" android:text="2"/>     <TextView android:layout_width="50dp" android:layout_height="50dp" android:background="#fffedcba" android:gravity="center" android:text="3"/> </FrameLayout>
android:gravity 来确定位置 上下左右。

12.RelativeLayout

1.使用容器间的相对位置。

2.内部属性:

    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_centerHorizontal 如果该值为true,该控件将被置于水平方向的中央    android:layout_centerInParent 如果该值为true,该控件将被置于父控件水平方向和垂直方向都居中    android:layout_centerVertical 如果该值为true,该控件将被置于垂直方向的中央

3.官网实例:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"                android:layout_width="fill_parent"                 android:layout_height="wrap_content"                android:background="@drawable/blue"                android:padding="10px" >    <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_background"              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>

效果:

第21天android:《android从零开始》视频(10-13)

12.RelativeLayout补充

13.Table.Layout学习

1.表格布局,以行和列来表示。

2.只有水平和竖直来排列。

3.如果tableRow 不在TableLayout里面。则只代表LinearLayout。

4.在布局中,如果需要文字在一条水平线上,可以使用 layout_alignbaseLine = "对应空间的id"

3.官网例子:

<?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="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>

结果:

第21天android:《android从零开始》视频(10-13)

更多相关文章

  1. Android交互式视觉设计控件二
  2. 关于Android开发的editText控件怎…
  3. android开发基础------相对布局属性
  4. Android 基本控件 View 类的常用xml 属性(初级详解)

随机推荐

  1. Android(安卓)Studio(七)Android(安卓)St
  2. Android事件分发机制详解:史上最全面、最
  3. Android(安卓)有效的解决内存泄漏的问题
  4. Android开发板之串口开发
  5. Android多分辨率适配实践【1】使用字体图
  6. Android(安卓)应用程序快速启动的秘诀
  7. 2010-03-02 传智播客—Android(四)数据存储
  8. 一切都“Android化”
  9. android 反编
  10. Android的参数大致分成两块:系统服务参数