Dhruv Tyagi Dhruv Tyagi -4 years ago 135
Android Question

how can i Acheive this Layout... Android

i am working on a android application and i want to create a xml like below one

enter image description here

and what i acheive is:

enter image description here

here is my XML Code:
and i use the

layout_weight
property but my imageView alignment is mismatch due the different textview size

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relative"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="40dp"
android:layout_weight="3"

>
<TextView
android:layout_width="wrap_content"
android:gravity="right"
android:id="@+id/serviceType"
android:layout_weight="1"
android:layout_height="wrap_content"
android:ellipsize="end"
/>
<ImageView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/margin"
android:src="@drawable/elipse"
android:layout_gravity="center"
android:layout_marginRight="@dimen/margin" />
<TextView
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="wrap_content"
android:textSize="@dimen/font_size"
/>


</LinearLayout>

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

<TextView
android:layout_width="wrap_content"
android:text="@string/vehicle_no"
android:textColor="@color/colorAccent"
android:layout_marginEnd="@dimen/margin"
android:textSize="@dimen/font_size"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="right"
android:id="@+id/textView10"
android:layout_marginRight="@dimen/margin" />

<ImageView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/margin"
android:src="@drawable/elipse"
android:layout_gravity="center"
android:layout_marginRight="@dimen/margin" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="26-JAN-2017"
android:layout_weight="1"
android:textColor="@color/colorAccent"
android:textStyle="bold"
android:textSize="@dimen/font_size"/>


</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_weight="3"
android:layout_gravity="center"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:text="@string/booking_id_name"
android:id="@+id/booking_id"
android:textColor="@color/colorAccent"
android:textSize="@dimen/font_size"
android:layout_marginEnd="@dimen/margin"
android:gravity="right"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/margin" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/elipse"
android:layout_marginEnd="@dimen/margin"
android:layout_weight="1"
android:layout_gravity="center"
android:layout_marginRight="@dimen/margin" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="26-JAN-2017"
android:textColor="@color/colorAccent"
android:textStyle="bold"
android:layout_weight="1"
android:textSize="@dimen/font_size"/>


</LinearLayout>


</LinearLayout>

Answer Source

Here you go, replace above code with this.

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/relative"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="40dp"
            android:layout_weight="5">
            <TextView
                android:layout_width="0dp"
                android:gravity="end"
                android:id="@+id/serviceType"
                android:layout_weight="2"
                android:layout_height="wrap_content"
                android:ellipsize="end" />
            <ImageView
                android:layout_weight="1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="@dimen/margin"
                android:src="@drawable/elipse"
                android:layout_gravity="center"
                android:layout_marginRight="@dimen/margin" />
            <TextView
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:layout_width="0dp"
                android:textSize="@dimen/font_size" />
        </LinearLayout>

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

            <TextView
                android:layout_width="0dp"
                android:text="@string/vehicle_no"
                android:textColor="@color/colorAccent"
                android:layout_marginEnd="@dimen/margin"
                android:textSize="@dimen/font_size"
                android:layout_weight="2"
                android:layout_height="wrap_content"
                android:gravity="right"
                android:id="@+id/textView10"
                android:singleLine="true"
                android:layout_marginRight="@dimen/margin" />

            <ImageView
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginEnd="@dimen/margin"
                android:src="@drawable/elipse"
                android:layout_gravity="center"
                android:layout_marginRight="@dimen/margin" />
            <TextView
                android:layout_height="wrap_content"
                android:layout_width="0dp"
                android:text="26-JAN-2017"
                android:layout_weight="2"
                android:textColor="@color/colorAccent"
                android:textStyle="bold"
                android:textSize="@dimen/font_size"/>


        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="10dp"
            android:layout_weight="5"
            android:layout_gravity="center"
            android:gravity="center">
            <TextView
                android:layout_width="0dp"
                android:singleLine="true"
                android:text="@string/booking_id_name"
                android:id="@+id/booking_id"
                android:textColor="@color/colorAccent"
                android:textSize="@dimen/font_size"
                android:layout_marginEnd="@dimen/margin"
                android:gravity="right"
                android:layout_weight="2"
                android:layout_height="wrap_content"
                android:layout_marginRight="@dimen/margin" />
            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:src="@drawable/elipse"
                android:layout_marginEnd="@dimen/margin"
                android:layout_weight="1"
                android:layout_gravity="center"
                android:layout_marginRight="@dimen/margin" />
            <TextView
                android:layout_height="wrap_content"
                android:layout_width="0dp"
                android:text="26-JAN-2017"
                android:textColor="@color/colorAccent"
                android:textStyle="bold"
                android:layout_weight="2"
                android:textSize="@dimen/font_size"/>


        </LinearLayout>

    </LinearLayout>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download