1.线性布局:<?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="match_parent" android:orientation="vertical" >    <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="按钮1" />    <Button  android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="right|center_vertical" android:text="按钮2" />    <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮3" />    <LinearLayout  android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" >        <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮1" />        <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="按钮2" />        <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" android:text="按钮3" />    </LinearLayout></LinearLayout>2.相对布局:<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >    <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="进攻" />    <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="左勾拳" />    <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:text="右勾拳" />    <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:text="逃跑" />    <Button  android:id="@+id/btn_bisha" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="大绝招" />    <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/btn_bisha" android:layout_alignTop="@id/btn_bisha" android:text="左" />    <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/btn_bisha" android:layout_centerHorizontal="true" android:text="上" />    <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/btn_bisha" android:layout_alignBaseline="@id/btn_bisha" android:text="右" />    <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/btn_bisha" android:layout_centerHorizontal="true" android:text="下" /></RelativeLayout>3.帧布局:<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >    <Button  android:layout_width="300px" android:layout_height="300px" android:layout_gravity="center" android:text="最底部" />    <Button  android:layout_width="150px" android:layout_height="150px" android:layout_gravity="center" android:text="中间" />    <Button  android:layout_width="50px" android:layout_height="50px" android:layout_gravity="center" android:text="顶部" /></FrameLayout>4.表格布局:<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:shrinkColumns="0" android:collapseColumns="0" >    <TableRow android:layout_height="wrap_content" >        <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一行, 0列" />        <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一行, 1列" />        <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一行, 2列" />        <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一行, 3列" />    </TableRow>    <TableRow android:layout_height="wrap_content" >        <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第二行, 0列" />        <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="2" android:layout_span="2" android:text="第二行, 1列" />    </TableRow></TableLayout>5.绝对布局:<?xml version="1.0" encoding="utf-8"?><AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >    <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="1dp" android:layout_y="253dp" android:text="按钮" /></AbsoluteLayout>6.dp与px:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" >    <Button  android:layout_width="160px" android:layout_height="wrap_content" android:text="单位是px" android:textSize="18px" />    <Button  android:layout_width="160dp" android:layout_height="wrap_content" android:text="单位是sp" android:textSize="18sp" /></LinearLayout>

更多相关文章

  1. android之【TableLayout布局】
  2. android 作业1相对布局(拼图)
  3. android - 头中尾布局
  4. Android仿计算器布局代码
  5. android的布局练习
  6. android之【RelativeLayout布局】
  7. Android 五大布局之(一) 线性布局和相对布局

随机推荐

  1. MySQL 8.0的关系数据库新特性详解
  2. MySQL服务器线程数的查看方法详解
  3. CentOS7环境下源码安装MySQL5.7的方法
  4. MySQL实现导出excel的方法分析
  5. MySQL触发器简单用法示例
  6. 利用mycat实现mysql数据库读写分离的示例
  7. mysql启动时出现ERROR 2003 (HY000)问题
  8. mysql 5.7.20 zip安装教程
  9. MySQL视图原理与基本操作示例
  10. mysql存储过程用法实例分析