Android XML: Multiple button layout

The layout :

Snipaste_2022-07-27_08-08-47

The xml code : 😃
(before using this code, you should create your drawable xml file for background )

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/linearLayout_button"
        android:layout_width="362dp"
        android:layout_height="263dp"
        android:layout_gravity="center"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">


        <Button
            android:id="@+id/button_f"
            android:layout_width="112dp"
            android:layout_height="90dp"
            android:layout_gravity="center"
            android:layout_margin="5dp"
            android:layout_weight="2"
            android:background="@drawable/button_selector"
            android:text="@string/f"
            android:textSize="20sp"
            android:textStyle="bold" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="90dp"
            android:gravity="center_horizontal"
            android:orientation="horizontal">

            <Button
                android:id="@+id/button_l"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_margin="5dp"
                android:layout_weight="2"
                android:background="@drawable/button_selector"
                android:text="@string/l"
                android:textSize="20sp"
                android:textStyle="bold" />

            <Button
                android:id="@+id/button_s"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_margin="5dp"
                android:layout_weight="2"
                android:background="@drawable/button_selector"
                android:text="@string/s"
                android:textColor="@android:color/holo_red_dark"
                android:textSize="20sp"
                android:textStyle="bold" />

            <Button
                android:id="@+id/button_r"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_margin="5dp"
                android:layout_weight="2"
                android:background="@drawable/button_selector"
                android:text="@string/r"
                android:textSize="20sp"
                android:textStyle="bold" />

        </LinearLayout>

        <Button
            android:id="@+id/button_b"
            android:layout_width="113dp"
            android:layout_height="90dp"
            android:layout_gravity="center"
            android:layout_margin="5dp"
            android:layout_weight="2"
            android:background="@drawable/button_selector"
            android:text="@string/b"
            android:textSize="20sp"
            android:textStyle="bold" />
    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
posted @ 2022-07-27 08:20  litecdows  阅读(47)  评论(0编辑  收藏  举报