簡體   English   中英

如何使xml中的2個按鈕以線性布局粘在一起(覆蓋整個空間)?

[英]How to make 2 buttons in xml stick together (cover the whole space) in a linear layout?

我試圖使線性布局中的2個按鈕一起出現,或者比現在彼此靠攏的位置更近,但是我正在努力做到這一點。

下面是我的xml及其顯示的內容,是否有可能實現我想要的內容,如果有人可以告訴我該怎么做,我將不勝感激。

 <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <Button
                android:text="Person 1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/btnPerson1" />

            <Button
                android:text="Person 2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/btnPerson2" />
        </LinearLayout>

我希望PERSON 1按鈕和PERSON 2按鈕關閉或粘在一起 在此處輸入圖片說明

將android:layout_margin =“ 0”添加到按鈕

為兩個按鈕設置負邊距。

android:layout_marginTop=-8dp
android:layout_marginBottom=-8dp

嘗試這個,

<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0dp">

        <Button
            android:text="Person 1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight=".5"
            android:id="@+id/btnPerson1" />

        <Button
            android:text="Person 2"
            android:layout_marginTop="-12dp"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight=".5"
            android:id="@+id/btnPerson2" />
    </LinearLayout>

暫無
暫無

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

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