溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

android的LinearLayout布局

發(fā)布時(shí)間:2020-10-06 15:07:02 來源:網(wǎng)絡(luò) 閱讀:361 作者:matengbing 欄目:移動(dòng)開發(fā)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="vertical" >
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/to" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/subject" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="top"
        android:hint="@string/message" />
    <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="@string/send" />
</LinearLayout>
<!--    android:orientation="vertical" 代表方向垂直-->
<!--  android:layout_weight="1" 代表所占權(quán)重(比例)    message占滿其他元素剩余的地方,
		如果有多個(gè)android:layout_weight=1,則平分剩余空間
		 android:gravity="top"表示從上面開始占(寫了android:layout_weight的)
		 
		 
		   android:layout_gravity="right"
		   整個(gè)組件的位置居右
-->

android的LinearLayout布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="horizontal" >
    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/to" />
    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/subject" />
    <EditText
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="top"
        android:hint="@string/message" />
    <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="@string/send" />
</LinearLayout>

android的LinearLayout布局

LinearLayout 是一個(gè)視圖組,它所有的子視圖都在一個(gè)方向?qū)R,水平或者垂直。你可以指定布局的方向通過 android:orientation 屬性。

LinearLayout的所有子視圖排列都是一個(gè)靠著另一個(gè),因此垂直列表每行僅僅有一個(gè)子視圖,不管有多寬。水平列表只能有一行的高度(最高子視圖的高度加上邊距距離)。LinearLayout 期望子視圖之間都有margin,每個(gè)子視圖都有gravity

線性布局支持給個(gè)別的子視圖設(shè)定權(quán)重,通過android:layout_weight屬性。就一個(gè)視圖在屏幕上占多大的空間而言,這個(gè)屬性給其設(shè)定了一個(gè)重要的值。一個(gè)大的權(quán)重值,允許它擴(kuò)大到填充父視圖中的任何剩余空間。子視圖可以指定一個(gè)權(quán)重值,然后視圖組剩余的其他的空間將會分配給其聲明權(quán)重的子視圖。默認(rèn)的權(quán)重是0.

例如,如果有三個(gè)文本框,其中兩個(gè)聲明的權(quán)重為1,另外一個(gè)沒有權(quán)重,沒有權(quán)重第三個(gè)文本字段不會增加,只會占用其內(nèi)容所需的面積。其他兩個(gè)同樣的會擴(kuò)大以填補(bǔ)剩余的空間,在三個(gè)文本域被測量后。如果第三個(gè)字段,然后給定的權(quán)重為2(而不是0),那么它現(xiàn)在的聲明比其他的更重要,所以它得到一半的總的剩余空間,而前兩個(gè)平均分配剩余的。



向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI