Android 布局(一):相對布局和線性布局

來源:互聯網
上載者:User

1、 RelativeLayout:相對布局
android:layout_above 將該控制項的底部 至於給定Id的控制項 之上
android:layout_below 將該控制項的頂部至於給定ID的控制項之下
android:layout_toLeftOf 將該控制項的右邊緣和給定ID的控制項的左邊緣對齊
android:layout_toRightOf將該控制項的左邊緣和給定ID的控制項的右邊緣對齊

android:layout_alignBaseline將該 控制項的baseline 和給定ID的控制項 的baseline對齊
android:layout_alignBottom將該控制項的底部邊緣與給定ID控制項的底部邊緣對齊
android:layout_alignLeft將該控制項的左邊緣與給定ID控制項的左邊緣對齊
android:layout_alignRight將該控制項的右邊緣與給定ID控制項的右邊緣對齊
android:layout_alignTop將該控制項的頂部邊緣與給定ID控制項的頂部邊緣對齊

android:alignParentBottom 如果該值為true,則將該控制項的底部和父控制項的底部對齊
android:layout_alignParentLeft 如果該什為true, 則將該控制項的左邊和父控制項的左邊對齊
android:layout_alignParentRight 如果該什為true, 則將該控制項的右邊和父控制項的右邊對齊
android:layout_alignParentTop 如果該什為true, 則將該控制項的頂部和父控制項的頂部對齊

android:layout_centerHorizontal如果值為真,該控制項將被至於水平方向的中央
android:layout_inParent如果值為真,該控制項將被至於父控制項水平方向和垂直方向的中央
android:layout_centerVertical如果值為真,該控制項將被至於垂直方向的中央

2、 LinearLayout:線性布局;

版本,編碼

 

android:orientation=vertical 方向是什麼,水平和垂直之分,

android:layout_width=fill_parent 寬度

android:layout_height=fill_parent 高度

>

android:id=@+id/firstText 為控制項指定相應ID

android:text=第一行 指定控制項當中顯示的文字,需要注意的是,這裡盡量使用string.xml

android:gravity=center_vertical 指定控制項的基本位置,比如說置中,居右等位置

android:textSize=35pt 指定控制項當中字型的大小

android:background=#aa0000 指定該 控制項所使用的背景顏色,RGB命名法

android:layout_width=fill_parent 充滿控制項

android:layout_height=warp_content保住內容

android:paddingLeft=10dip指定控制項的內邊距,也就是說控制項的當中的位置

android:layout_weight=1 位置是1 做為兩個控制項,兩件控制項一起充滿著,但是有百分比

android:singleLine=true如果設定為真的話,則將控制項的內容在同一行不如進行顯示


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.