1.线性布局LinearLayout

android:orientation="horizontal" >    android:layout_weight="1"        android:hint="Type something" />        

属性解释:

android:orientation="horizontal"//控件水平排列
android:orientation="vertical"//控件垂直排列

   

 android:layout_weight="1"//若多个控件用layout_weight,则按此所占总和宽度的比例排布。此例只一个控件用此属性,则horizontal水平方向占满Button剩下的全部比例。

2.相对布局RelativeLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent" >        
这些按钮通过父布局Parent进行定位,效果图如下:

另外,如果要指定控件垂直或水平方向在整体布局中的对齐方式(要先指定了水平对齐horizontal或垂直对齐vertical),可用android:layout_gravity属性。

android:layout_gravity="top"

android:layout_gravity="center_vertical"

android:layout_gravity="bottom"

也可以相对于控件进行定位:

        
另外四个按钮都相对于Button3定位,效果图如下:


3.框架布局FrameLayout

        

所有控件都会摆放在布局的左上角,即使使用了定位的属性(例如android:layout_below="@id/button3"     android:layout_toLeftOf="@id/button3"也会失效)

效果如下:

五个按钮都堆叠在了左上角(后堆的覆盖在先堆的上面)。

4.表格布局TableLayout

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent" >                                                                
注意:TableRow内的控件不能指定宽度。

每加入一对 就增加一行。

此例为三行两列的表格,其中第三行只有一个Button按钮,因此使用layout_span="2"对单元格合并,效果如下:



然而此时表格右边空出一片没填满,而TableRow内控件又不能指定宽度,可加一句android:stretchColumns="x"意思为当行宽度未填满时可自动拉伸第x+1列。

例如刚刚的例子要拉伸第二列,即编辑框EditText,则加android:stretchColumns="1"

android:stretchColumns="1" >                                                                
效果如下:

总结一下,四种基本布局有:

1.线性布局LinearLayout
2.相对布局RelativeLayout

3.框架布局FrameLayout

4.表格布局TableLayout

更多相关文章

  1. Android(安卓)TextView属性大全
  2. TextView控件的使用(Android设置文本显示格式)
  3. android_控件属性
  4. Android中的android:layout_width和android:width
  5. Android中的android:layout_width和android:width
  6. ListView点击事件不响应。
  7. android listview 控件触摸滑动出现白屏问题
  8. Android中的android:layout_width和android:width
  9. android常用控件

随机推荐

  1. android 开发实用
  2. 输入法问题
  3. 生成Google Map KeyGen
  4. Android之MediaCodec使用经验分享
  5. Android7 增加双以太网eth1的支持
  6. Android8.0 页面崩溃问题
  7. android 截屏
  8. Android中Intent的各种常见作用
  9. App Inventor for Android(安卓)使用总结
  10. Android常用UI组件 - EditText