Android XML: Multiple button layout
The layout :
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>
本文来自博客园,作者:litecdows,作者在其他博客平台均使用此昵称!
转载请注明原文链接:https://www.cnblogs.com/litecdows/p/16523386.html