Amardeepvijay
Amardeepvijay

Reputation: 1628

Android Linear layout image with text

I am making an android app, i want to make a layout like below image.

How can i manage image and layout weight with color.enter image description here

Upvotes: 0

Views: 1958

Answers (1)

Hariharan
Hariharan

Reputation: 24853

Try this..

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/flag"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:src="@drawable/ic_launcher" />

            <TextView
                android:id="@+id/txt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:background="#1D63A1"
                android:gravity="center"
                android:padding="7dp"
                android:text="@string/hello_world"
                android:textColor="#FFFFFF"
                android:textSize="20dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/flag"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:src="@drawable/ic_launcher" />

            <TextView
                android:id="@+id/txt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:background="#1D63A1"
                android:gravity="center"
                android:padding="7dp"
                android:text="@string/hello_world"
                android:textColor="#FFFFFF"
                android:textSize="20dp" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/flag"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:src="@drawable/ic_launcher" />

            <TextView
                android:id="@+id/txt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:background="#1D63A1"
                android:gravity="center"
                android:padding="7dp"
                android:text="@string/hello_world"
                android:textColor="#FFFFFF"
                android:textSize="20dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/flag"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:src="@drawable/ic_launcher" />

            <TextView
                android:id="@+id/txt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:background="#1D63A1"
                android:gravity="center"
                android:padding="7dp"
                android:text="@string/hello_world"
                android:textColor="#FFFFFF"
                android:textSize="20dp" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

Upvotes: 2

Related Questions