简体   繁体   中英

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

I am trying to make 2 buttons in a linear layout appear together or be closer then where there are now against each other but I am struggling to do so.

below is my xml with what it shows, is it possible to achieve what I want, I would really appreciate if someone could tell me how.

 <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>

I want the PERSON 1 button and PERSON 2 button to come closes and or stick together 在此处输入图片说明

将android:layout_margin =“ 0”添加到按钮

Set negative margin to both buttons.

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

Try this,

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM