Nikhil
Nikhil

Reputation: 167

Android layout design : Using LinearLayout and Relative layout

I want to have a layout exactly similar to one below in image. I've tried the below code but it is not coming. Can someone help me in getting this layout.

Layout required

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="6dip" >

    <TextView
        android:id="@+id/firstLine"
        android:layout_width="fill_parent"
        android:layout_height="26dip"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:text="Ali Connors"
        android:textSize="12sp" />

    <TextView
        android:id="@+id/secondLine"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/firstLine"
        android:gravity="center_vertical"
        android:text="Brunch this weekend?"
        android:textSize="16sp" />

    <TextView
        android:gravity="right"
        android:id="@+id/rightTime"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="15m"
        android:textSize="16sp" />

</RelativeLayout>

Upvotes: 0

Views: 213

Answers (3)

Ferdous Ahamed
Ferdous Ahamed

Reputation: 21736

Design your Layout as below:

<?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="wrap_content"
    android:orientation="vertical">

    <View
        android:layout_width="match_parent"
        android:layout_height="4dp"
        android:background="#FF4081" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp">

        <TextView
            android:id="@+id/rightTime"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="15m"
            android:textSize="14sp"
            android:textColor="#727272"/>

        <TextView
            android:id="@+id/firstLine"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@id/rightTime"
            android:layout_marginRight="8dp"
            android:maxLines="1"
            android:ellipsize="end"
            android:text="Ali Connors"
            android:textSize="16sp"
            android:textColor="#000000"/>

        <TextView
            android:id="@+id/secondLine"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/firstLine"
            android:layout_marginTop="2dp"
            android:text="Brunch this weekend?"
            android:textSize="16sp"
            android:textColor="#000000"
            android:maxLines="1"
            android:ellipsize="end" />

        <ImageView
            android:id="@+id/image_star"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_below="@id/secondLine"
            android:layout_alignParentRight="true"
            android:background="@android:drawable/star_big_off" />

        <TextView
            android:id="@+id/thirdLine"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/secondLine"
            android:layout_toLeftOf="@id/image_star"
            android:layout_marginTop="4dp"
            android:layout_marginRight="16dp"
            android:text="I will be in your neighborhood doing some errands....."
            android:textColor="#727272"
            android:textSize="14sp"
            android:maxLines="1"
            android:ellipsize="end" />
    </RelativeLayout>
</LinearLayout>

Output:

enter image description here

Upvotes: 0

rafsanahmad007
rafsanahmad007

Reputation: 23881

try the following:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <View
        android:layout_width="match_parent"
        android:layout_height="4dp"
        android:background="#ED262A" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="6dp">

        <TextView
            android:id="@+id/firstLine"
            android:layout_width="fill_parent"
            android:layout_height="26dp"
            android:layout_alignParentLeft="true"
            android:layout_marginTop="5dp"
            android:ellipsize="marquee"
            android:singleLine="true"
            android:text="Ali Connors"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/secondLine"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/firstLine"
            android:gravity="center_vertical"
            android:text="Brunch this weekend?"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/thirdLine"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/secondLine"
            android:drawablePadding="6dp"
            android:drawableRight="@android:drawable/star_off"
            android:gravity="center_vertical"
            android:text="I will be in the place"
            android:textColor="#A4A18E"
            android:textSize="14sp" />


        <TextView
            android:id="@+id/rightTime"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:layout_alignParentRight="true"
            android:gravity="top|right"
            android:text="15m"
            android:textSize="16sp" />

    </RelativeLayout>

</LinearLayout>

enter image description here

Upvotes: 5

sHOLE
sHOLE

Reputation: 343

Try this.

    <TextView
    android:text="15m"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:id="@+id/rightTime"
    android:textSize="16sp"/>

Upvotes: 0

Related Questions