Create two buttons of equal size inside Linear Layout in Android

Following code we used to create two buttons we use to select the Gender of user during registration,

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_marginTop="@dimen/_10sdp"
    android:weightSum="2"
    android:orientation="horizontal">
    <Button
        android:id="@+id/buttonMale"
        android:layout_weight="1"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:gravity="center"
        android:layout_marginTop="20dp"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:layout_marginRight="20dp"
        android:elevation="10dp"
        android:text="Male"
        android:textColor="@color/colorWhite"
        android:fontFamily="@font/sourceserifpro_regular"
        app:icon="@drawable/svg_heart_border"
        style="@style/Widget.MaterialComponents.Button.Icon"
        android:textSize="20dp" />
    <Button
        android:id="@+id/buttonFemale"
        android:layout_weight="1"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:gravity="center"
        android:layout_marginTop="20dp"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:elevation="10dp"
        android:text="Female"
        android:textColor="@color/colorWhite"
        android:fontFamily="@font/sourceserifpro_regular"
        app:icon="@drawable/svg_heart_border"
        style="@style/Widget.MaterialComponents.Button.Icon"
        android:textSize="20dp" />
</LinearLayout>

As you can see in LinearLayout we have set, android:weightSum=”2″ and then in each of the button we set android:layout_weight=”1″ to make those of equal size, and also another important is android:layout_width=”0dip”

For using Material view for this buttons we have set the theme as,

        app:icon="@drawable/svg_heart_border"
        style="@style/Widget.MaterialComponents.Button.Icon"
android change whole app language ... x
android change whole app language locale in android - PART 2

Leave a Comment

Sign up to our newsletter!

ADB Commands Android Android Applications Android Build system Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development, Debugging and Performance Tools Development and Build Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia NDK / Middleware / HAL Operating System Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web Design and Development Website Hosting Wordpress Yocto Embedded Linux