I am trying to get the following design. Consider that it is a list item.
But my following design, it does not give me that design.The textviews come on the top of left image.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_person_black_24dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:id="@+id/userimage" />
<TextView
android:text="Text1"
android:layout_toRightOf="@id/userimage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/username"/>
<TextView
android:text="Text2"
android:layout_below="@id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_keyboard_arrow_right_black"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout >
Instead of a LinearLayout use a RelativeLayout, and for the TextViews use:
android:layout_toRightOf="@id/userimage" and
android:layout_alignTop="@id/userimage" or
android:layout_alignBottom="@id/userimage"
Here you go:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="horizontal">
<ImageView
android:id="@+id/userimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_person_black_24dp"
tools:background="@mipmap/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignBottom="@id/userimage"
android:layout_toEndOf="@id/userimage"
android:layout_toStartOf="@id/arrow"
android:orientation="vertical">
<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center|start"
tools:text="Text1" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center|start"
tools:text="Text2" />
</LinearLayout>
<ImageView
android:id="@+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_keyboard_arrow_right_black"
tools:background="@mipmap/ic_launcher" />
</RelativeLayout>
Try to play with different layouts when you have time, it will help you greatly in the future.
Edit : Better solution for centering TextViews.
Try this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dip" >
<ImageView
android:id="@+id/userimage"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="6dip"
android:contentDescription="TODO"
android:src="@drawable/ic_person_black_24dp" />
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="6dip"
android:contentDescription="TODO"
android:src="@drawable/ic_keyboard_arrow_right_black" />
<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_above="@id/secondline"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/userimage"
android:layout_toLeftOf="@id/icon"
android:singleLine="true"
android:gravity="center_vertical"
android:text="Example username"
android:textSize="16sp" />
<TextView
android:id="@+id/secondline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="1"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/userimage"
android:layout_toLeftOf="@id/icon"
android:singleLine="true"
android:text="Description"
android:textSize="12sp" />
</RelativeLayout>
I used some dp
sizes that you did not use and added a few other things, but I guess you can change it so that it suits your desire. I did try use the same names as you did. Overall this should work if you tweak it a bit.
Your problem in text2 use it , it would work
<TextView
android:text="Text2"
android:layout_below="@id/username"
android:layout_toRightOf="@id/userimage"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.