【Android基础】页面布局

来源:互联网 发布:mac设置文件夹加密 编辑:程序博客网 时间:2024/06/06 02:13

线性布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"       android:layout_width="match_parent"    android:layout_height="wrap_content">   <!-- 垂直的线性布局 -->    <Button        android:id="@+id/next"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="@string/line_str1">    </Button>    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="horizontal"       android:layout_width="wrap_content"    android:layout_height="wrap_content">   <!-- 水平的线性布局 -->    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/line_str2">    </Button>    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/line_str3">    </Button>    </LinearLayout></LinearLayout>

表格布局

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent">   <!-- 表格布局 -->    <TextView        android:id="@+id/textView1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:gravity="center"        android:text="@string/table_str1">    </TextView>  <!-- 表头 -->    <TableRow        android:gravity="center">        <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/table_str2">        </TextView>        <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/table_str3">        </TextView>    </TableRow>   <!-- 添加一行 --></TableLayout>

相对布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent" >    <TextView        android:id="@+id/textView"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerInParent="true"        android:padding="@dimen/padding_medium"        android:text="@string/hello_world"        tools:context=".RelativeActivity" />    <Button        android:id="@+id/back1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/relative_str1"        android:layout_above="@id/textView"        android:layout_alignLeft="@id/textView">    </Button>    <Button        android:id="@+id/next2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/relative_str2"        android:layout_below="@id/textView"        android:layout_alignRight="@id/textView">    </Button></RelativeLayout>

单帧布局

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent" >    <ImageView         android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:src="@drawable/ic_launcher"        android:contentDescription="@string/hello_world"/>    <Button        android:id="@+id/next3"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/relative_str2">    </Button></FrameLayout>

坐标布局

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent" >    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_x="30dp"        android:layout_y="50dp"        android:padding="@dimen/padding_medium"        android:text="@string/hello_world"        tools:context=".AbsoluteActivity" /></AbsoluteLayout>

原创粉丝点击