您的位置:首页 > 其它

2016-04-25Andriod基础 三种布局

2016-04-25 23:33 274 查看
线性布局

<LinearLayout 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"
tools:context="com.example.linearlayout.MainActivity"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ff0000"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff0000"/>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#123456"/>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="#789876"/>

</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#00ff00"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ff0000"/>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#123456"/>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#789876"/>

</LinearLayout>

</LinearLayout>


相对布局

<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">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左上"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="右上"
android:layout_alignParentRight="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左下"
android:layout_alignParentBottom="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="右下"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>

<Button
android:id="@+id/bt_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="居中"
android:layout_centerInParent="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="居左"
android:layout_alignTop="@id/bt_center"
android:layout_toLeftOf="@id/bt_center"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="居右"
android:layout_alignTop="@id/bt_center"
android:layout_toRightOf="@id/bt_center"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="居上"
android:layout_alignLeft="@id/bt_center"
android:layout_above="@id/bt_center"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="居下"
android:layout_alignLeft="@id/bt_center"
android:layout_below="@id/bt_center"/>

</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">

<View
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#ff0000"
/>
<View
android:layout_gravity="center"
android:layout_width="150dp"
android:layout_height="150dp"
android:background="#ffff00"
/>
<View
android:layout_gravity="center"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#ffffff"
/>
<View
android:layout_gravity="center"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#00ff00"
/>

</FrameLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: