android(3)(android五大布局)

来源:互联网 发布:剑灵捏脸动漫人物数据 编辑:程序博客网 时间:2024/04/30 03:09
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>
0 0
原创粉丝点击