標籤:xmlns 技術 技術分享 使用 com res android abs androi
一.AbsoluteLayout(絕對布局)重點:
AbsoluteLayout(絕對布局)之所以把這個放到最後,是因為絕對布局,我們基本上都是不會使用的,我們開發的應用需要在很多的機型上面進行一個適配,如果你使用了這個絕對布局的話,可能你在4寸的手機上是顯示正常的,而換成5寸的手機,就可能出現位移和變形,所以的話,這個還是不建議使用了
二.AbsoluteLayout(絕對布局)常用屬性:
控制大小:
android:layout_width:組件寬度 android:layout_height:組件高度
控制位置:
android:layout_x:設定組件的X座標 android:layout_y:設定組件的Y座標
三.例子(主要呈現android:layout_x、android:layout_y控制控制項的位置)
1.首先我們先建立一個AbsoluteLayout的XML檔案
代碼如下:
1 <?xml version="1.0" encoding="utf-8"?> 2 <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" > 5 6 <Button 7 android:id="@+id/button1" 8 android:layout_width="wrap_content" 9 android:layout_height="wrap_content"10 android:layout_x="32dp"11 android:layout_y="53dp"12 android:text="Button" />13 14 <Button15 android:id="@+id/button2"16 android:layout_width="wrap_content"17 android:layout_height="wrap_content"18 android:layout_x="146dp"19 android:layout_y="53dp"20 android:text="Button" />21 22 <Button23 android:id="@+id/button3"24 android:layout_width="wrap_content"25 android:layout_height="wrap_content"26 android:layout_x="85dp"27 android:layout_y="135dp"28 android:text="Button" />29 30 </AbsoluteLayout>
運行結果如下:
以上就是我對AbsoluteLayout(絕對布局)理解
Android五大布局之一絕對布局(AbsoluteLayout)