Android linear layout example

linear.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="4"
    tools:context="com.example.pc.myapplication.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal">

        <Button
            android:id="@+id/b1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="1"
            android:textSize="20dp"
            android:background="@drawable/color"
            android:textColor="#fff"/>

        <Button
            android:id="@+id/b2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="2"
            android:textSize="20dp"
            android:background="@drawable/color"
            android:textColor="#fff"/>

        <Button
            android:id="@+id/b3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="3"
            android:textSize="20dp"
            android:background="@drawable/color"
            android:textColor="#fff"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:textSize="20dp">

        <Button
            android:id="@+id/b4"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="4"
            android:textSize="20dp"
            android:background="@drawable/color"
            android:textColor="#fff"/>

        <Button
            android:id="@+id/b5"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="5"
            android:textSize="20dp"
            android:background="@drawable/color"
            android:textColor="#fff"/>

        <Button
            android:id="@+id/b6"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="6"
            android:textSize="20dp"
            android:background="@drawable/color"
            android:textColor="#fff"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal">

        <Button
            android:id="@+id/b7"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="7"
            android:textSize="20dp"
            android:background="@drawable/color"
            android:textColor="#fff"/>

        <Button
            android:id="@+id/b8"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="8"
            android:textSize="20dp"
            android:background="@drawable/color"
            android:textColor="#fff"/>

        <Button
            android:id="@+id/b9"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="9"
            android:textSize="20dp"
            android:background="@drawable/color"
            android:textColor="#fff"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:paddingLeft="130dp"
        android:paddingRight="130dp">

        <Button
            android:id="@+id/b0"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="0"
            android:textSize="20dp"
            android:background="@drawable/color"
            android:textColor="#fff"/>
    </LinearLayout>

</LinearLayout>

0 comments: