android菜鸟教程_菜鸟软件下载app(Android)
相對布局是通過相對定位的方式讓控件出現在布局任意位置;
在相對布局中如果不指定控件擺放的位置,那么控件都會被默認放在RelativeLayout的左上角。因此要先指定第一個控件的位置,其他控件為該位置的相對位置;
RelativeLayout屬性:
(使用相對布局屬性需要先指定控件的id,其他控件根據該控件的id,來確定相對于該控件的相對位置)
示例:
<?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">
<TextView android:id="@+id/textview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="第一個"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/textview" android:text="第二個"/>
</RelativeLayout>
Jetbrains全家桶1年46,售后保障穩定
結果:
(第一個控件默認在布局左上角,如果指定放在第一個控件的左邊或者上面,會看不到第二個控件)
與兄弟控件的邊緣對齊:
android:layout_below 將該控件的上邊緣對齊指定控件的下邊緣
android:layout_above 將該控件的下邊緣對齊指定控件的上邊緣
android:layout_toLeftOf 將該控件的右邊緣對齊指定控件的左邊緣
android:layout_toRightOf 將該控件的左邊緣對齊指定空間的右邊緣
——–
android:layout_alignRight 將該控件的右邊緣對齊指定控件的右邊緣
如:
android:layout_alignLeft 將該控件的左邊緣對齊指定控件的左邊緣
android:layout_alignTop 將該控件的上邊緣對齊指定控件的上邊緣
android:layout_alignBottom 將該控的下邊緣對齊指定控件的下邊緣
————————
與父控件的邊緣對齊:
android:layout_alignParentLeft 左邊緣與父控件的左邊緣對齊
android:layout_alignParentRight右邊緣與父控件的右邊緣對齊
android:layout_alignParentTop上邊緣與父控件的上邊緣對齊
android:layout_alignParentBottom下邊緣與父控件的下邊緣對齊
(屬性值為true,false)
(可以同時使用兩個屬性,如android:layout_alignParentRight android:layout_alignParentBottom 表示將該控件放到父控件的右下角)
———————
對齊置父控件的中間:
android:layout_centerInParent放置到父控件的正中間
android:layout_centerHorizontal
放置到父控件的水平中間
android:layout_centerVertical放置到父控件的垂直中間
(屬性值為true,false)
———————
android:layout_alignStart對齊置兄弟控件的起始位置
android:layout_alignEnd對齊置兄弟控件的末尾位置
android:layout_alignParentStart對齊置父控件的起始位置
android:layout_alignParentEnd對齊置父控件的末尾位置
———————
基準線
android:layout_alignBaseline 對齊基準線
(值為id)
示例:
<TextView android:id="@+id/textview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="50sp" android:text="ABCDE"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/textview" android:layout_alignBaseline="@id/textview" android:text="cdefghil"/>
(圖中虛線為基準線)
總結
以上是生活随笔為你收集整理的android菜鸟教程_菜鸟软件下载app(Android)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: zip文件加密的几种破解方法(Bandi
- 下一篇: 未来的能量块,也许是一杯甲醇