日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android 4个布局,Android - 4种基本布局

發(fā)布時間:2023/12/15 Android 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 4个布局,Android - 4种基本布局 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1.線性布局

LinearLayout:線性布局

android:orientation="horizontal"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/button3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="top"

android:text="Button"/>

android:id="@+id/button4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_vertical"

android:text="Button"/>

android:id="@+id/button5"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="bottom"

android:text="Button"/>

EditText 和 Button 的 android:layout_weight 屬性都為1,表示水平方向各占1/2

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal">

android:id="@+id/editText"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:hint="Type something"

/>

android:id="@+id/send"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Send"

android:textAllCaps="false"

/>

最理想的布局:

Button只占其自身內容大小的寬,其余的寬由EditText占用

android:id="@+id/editText"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:hint="Type something"

/>

android:id="@+id/send"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Send"

android:textAllCaps="false"

/>

2.相對布局

RelativeLayout :相對布局

相對父視圖上、下、左、右

android:layout_alignParentTop="true"。

android:layout_alignParentBottom="true"

android:layout_alignParentLeft="true"

android:layout_alignParentRight="true"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/button6"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button"

android:layout_alignParentTop="true"

android:layout_alignParentLeft="true"/>

android:id="@+id/button7"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_alignParentTop="true"

android:text="Button"/>

android:id="@+id/button8"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:text="Button"/>

android:id="@+id/button9"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_alignParentLeft="true"

android:text="Button"/>

android:id="@+id/button10"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_alignParentRight="true"

android:text="Button"/>

相對于另一個控件。

android:layout_toLeftOf="@id/button6"。相對button6在它左邊

android:layout_toRightOf="@id/button6"。在button6右邊

android:layout_above。在上面

android:layout_below。在下面

android:layout_alignBottom。同底

android:layout_alignRight。同右

android:layout_alignLeft。同左

android:layout_alignTop。同頂

android:id="@+id/button6"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button6"

android:layout_centerInParent="true"/>

android:id="@+id/button7"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button7"

android:layout_toLeftOf="@id/button6"

android:layout_above="@id/button6"/>

android:id="@+id/button8"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toRightOf="@id/button6"

android:layout_above="@id/button6"

android:text="Button8"/>

android:id="@+id/button9"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/button6"

android:layout_toLeftOf="@id/button6"

android:text="Button9"/>

android:id="@+id/button10"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBottom="@id/button6"

android:layout_toRightOf="@id/button6"

android:text="Button10"/>

3.幀布局

android:layout_gravity。可選值:

bottom、left、right、top

center、center_horizontal、center_vertical

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/button6"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="bottom"/>

4.百分比布局

PercentFrameLayout。繼承幀布局的內容并可以使用百分比屬性(相對父視圖占用)。

app:layout_widthPercent="%50"

app:layout_heightPercent="%50"

PercentRelativeLayout。道理同PercentFrameLayout。

引入布局

。@layout/title中,title為一個xml文件名.

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結

以上是生活随笔為你收集整理的android 4个布局,Android - 4种基本布局的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。