簡體   English   中英

Android中的LinearLayout間距

[英]Linearlayout spacing in Android

這是我的布局:

的TextView

IMAGEVIEW(可選)

LINEARLAYOUT-我向其動態添加按鈕

LINEARLAYOUT-並排有兩個按鈕(左按鈕和右按鈕)

我需要做什么以確保底部的兩個線性布局固定在屏幕的底部,而不管它們可能占用多少空間? 即。 第一個線性布局可能有3個按鈕,占據屏幕的一半以上,這是可以的。 它只需要位於最后一個線性布局中的固定在底部的左/右按鈕上方。

然后,我希望我的TextView和ImageView在剩余空間中垂直居中。 如果沒有圖像,則將ImageView設置為不可見,因此只能是需要居中的文本視圖。

我一直在玩android:gravity =“ bottom”,android:layout_height =“ 0dip” / android:layout_weight =“ 1”(后來我意識到這只會給text / imageview提供50%, 2個線性布局),但我無法獲得理想的結果。

任何建議表示贊賞。

您必須采用RelativeLayout 在那里,您可以更好地控制視圖的相對位置,如下所示:

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
>
    <TextView 
        android:id="@+id/textView"
        android:layout_above="@+id/imageView"
        android:layout_centerVertical="true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    />

    <ImageView 
        android:id="@+id/imageView"
        android:layout_above="@+id/ll_1"
        android:layout_centerVertical="true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    />

    <LinearLyout 
        android:id="@+id/ll_1"
        android:layout_above="@+id/ll_2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    />

    <LinearLyout 
        android:id="@+id/ll_2"
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    />


</RelativeLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM