2 buttons side by side - android layouts

前端 未结 4 815
[愿得一人]
[愿得一人] 2020-12-24 01:33

how can I put 2 buttons side by side, so that they occupy all the width, with a little space between them..

I thought a horiz linear layout, with 2 sub linear layout

相关标签:
4条回答
  • 2020-12-24 02:17

    Try this,

    Make a RelaiveLayout orientation as horizontal and the give some padding to have a space between them..

    Make the Layoutheight and Layoutwidth of ur wish

    Thanks

    0 讨论(0)
  • 2020-12-24 02:18
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal" >
    
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:text="button1"
        android:id="@+id/button" />
    
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:text="button2"
        android:id="@+id/button2" />
    
    </LinearLayout>
    
    0 讨论(0)
  • 2020-12-24 02:21
    <LinearLayout 
        android:id="@+id/LinearLayout02" 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent" 
        android:layout_alignParentBottom="true">
        <Button 
            android:id="@+id/Button02" 
            android:layout_width="match_parent" 
            android:layout_height="wrap_content" 
            android:layout_weight="1" android:text="Apply">
        </Button>
        <Button 
            android:id="@+id/Button03" 
            android:layout_width="match_parent" 
            android:layout_height="wrap_content"
            android:layout_weight="1" 
            android:text="Cancel">
        </Button>
    </LinearLayout>
    
    0 讨论(0)
  • 2020-12-24 02:22

    If you want that the 2 buttons ocuppy all the width and the buttons have the same width, you must change in the 2 buttons the propertie:

    android:layout_width="wrap_content" to android:layout_width="match_parent"

    because if you have one of this button with a long text and the other button with short text, the button with long text ocuppy more space.

    0 讨论(0)
提交回复
热议问题