Veronika Gilbert
Veronika Gilbert

Reputation: 471

Mismatch in heights of ImageViews in Linear layout

Here I am trying to display 4 ImageViews in two different linear layouts enclosed in a parent layout (with vertical orientation). But there seems to be a mismatch in heights. How can I resolve this?

enter image description here

Here is my xml code snippet:

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/empinfo_logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="5dp"
            android:contentDescription="@string/Homescreen_emp_info"
            android:gravity="right"
            android:src="@drawable/employee_info" />

        <ImageView
            android:id="@+id/leaveinfo_logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="10dp"
            android:contentDescription="@string/Homescreen_leave_info"
            android:gravity="left"
            android:src="@drawable/leave_info" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/holidays_logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="5dp"
            android:contentDescription="@string/Homescreen_holidays"
            android:src="@drawable/holidays" />

        <ImageView
            android:id="@+id/leavereq_logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="10dp"
            android:contentDescription="@string/Homescreen_leave_req"
            android:gravity="left"
            android:src="@drawable/leave_request" />
    </LinearLayout>

NOTE: The dimensions of all the images are same.

Upvotes: 1

Views: 45

Answers (3)

Gopal Singh
Gopal Singh

Reputation: 1133

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="2"
    android:orientation="vertical" >
   <LinearLayout
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:layout_height="0dp"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:weightSum="2"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/empinfo_logo"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="5dp"
            android:contentDescription="@string/Homescreen_emp_info"
            android:gravity="right"
            android:src="@drawable/employee_info" />

        <ImageView
            android:id="@+id/leaveinfo_logo"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="10dp"
            android:contentDescription="@string/Homescreen_leave_info"
            android:gravity="left"
            android:src="@drawable/leave_info" />
    </LinearLayout>

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

        <ImageView
            android:id="@+id/holidays_logo"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:layout_marginRight="5dp"
            android:contentDescription="@string/Homescreen_holidays"
            android:src="@drawable/holidays" />

        <ImageView
            android:id="@+id/leavereq_logo"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"
            android:layout_marginLeft="5dp"
            android:contentDescription="@string/Homescreen_leave_req"
            android:gravity="left"
            android:src="@drawable/leave_request" />
    </LinearLayout>
    </LinearLayout>

Upvotes: 0

Anjali
Anjali

Reputation: 598

Use this code:

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/empinfo_logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/Homescreen_emp_info"
            android:layout_marginRight="5dp"
            android:gravity="right"
            android:src="@drawable/employee_info" />

        <ImageView
            android:id="@+id/leaveinfo_logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:contentDescription="@string/Homescreen_leave_info"
            android:gravity="left"
            android:src="@drawable/leave_info" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/holidays_logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:contentDescription="@string/Homescreen_holidays"
            android:src="@drawable/holidays" />

        <ImageView
            android:id="@+id/leavereq_logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:contentDescription="@string/Homescreen_leave_req"
            android:gravity="left"
            android:src="@drawable/leave_request" />
    </LinearLayout>

Upvotes: 1

Jai
Jai

Reputation: 486

image view set size width and heigth following bellow

<ImageView
        android:id="@+id/leaveinfo_logo"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="10dp"
        android:contentDescription="@string/Homescreen_leave_info"
        android:gravity="left"
        android:src="@drawable/leave_info" />

Upvotes: 0

Related Questions