Android中的相对布局
生活随笔
收集整理的這篇文章主要介紹了
Android中的相对布局
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 1 Android中的相對布局
- 1.1 相對布局的重要屬性
- 1.2 相對布局示例
1 Android中的相對布局
1.1 相對布局的重要屬性
相對于父容器(取值:true/false),如:
- android:layout_alignParentRight
相對于其他控件(取值:其他控件id),如:
- android:layout_toRightOf
1.2 相對布局示例
XML文件如下:
<?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"><!--android:layout_centerInParentandroid:layout_alignParentLeftandroid:layout_alignParentRightandroid:layout_alignParentTopandroid:layout_alignParentBottomandroid:layout_centerHorizontalandroid:layout_centerVertical--><TextViewandroid:id="@+id/center"android:layout_width="100dp"android:layout_height="100dp"android:textSize="30sp"android:text="屏幕正中"android:background="#ff0000"android:layout_centerInParent="true"/><!--1.在參照物的某邊android:layout_toLeftOfandroid:layout_toRightOfandroid:layout_aboveandroid:layout_below2.和參照物的某邊線對齊android:layout_alignTopandroid:layout_alignBottomandroid:layout_alignLeftandroid:layout_alignRight--><TextViewandroid:layout_width="100dp"android:layout_height="100dp"android:textSize="30sp"android:text="中偏左上"android:background="#00ff00"android:layout_above="@id/center"android:layout_toLeftOf="@id/center"/><TextViewandroid:layout_width="100dp"android:layout_height="100dp"android:textSize="30sp"android:text="中偏右上"android:background="#00ff00"android:layout_above="@id/center"android:layout_toRightOf="@id/center"/><TextViewandroid:layout_width="100dp"android:layout_height="100dp"android:textSize="30sp"android:text="中偏左下"android:background="#00ff00"android:layout_below="@id/center"android:layout_toLeftOf="@id/center"/><TextViewandroid:layout_width="100dp"android:layout_height="100dp"android:textSize="30sp"android:text="中偏右下"android:background="#00ff00"android:layout_below="@id/center"android:layout_toRightOf="@id/center"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="和中間上邊線對齊"android:background="#0000ff"android:layout_alignRight="@id/center"/></RelativeLayout>總結
以上是生活随笔為你收集整理的Android中的相对布局的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android中的线性布局
- 下一篇: 盱眙县是怎么读的?