Issue
I am working with a ListView item layout, but I can't arrange the child positions in a Relativelayout.
Here is my Item Layout frame:
I want The First ImageView on the top, one TextView in center, and the second ImageView on the bottom.
Here is my layout code(The Green RelativeLayout)
<RelativeLayout
android:id="@+id/bub_right"
android:layout_width="30dip"
android:layout_height="wrap_content"
android:layout_alignTop="@id/bub_left"
android:layout_alignBottom="@id/bub_left"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="#666666"
android:gravity="right">
<ImageView
android:layout_width="30dip"
android:layout_height="20dip"
android:id="@+id/bub_up"
android:layout_alignParentTop="true"
android:src="@drawable/up"/>
<TextView
android:layout_width="30dip"
android:layout_height="20dip"
android:text="123"
android:layout_centerVertical="true"
android:id="@+id/bub_score"
android:textSize="15dp"/>
<ImageView
android:id="@+id/bub_down"
android:layout_width="30dip"
android:layout_alignParentBottom="true"
android:layout_height="20dip"
android:src="@drawable/down"/>
</RelativeLayout>
I set these two lines to make sure The Green Relativelayout has the same height as the Red one.
android:layout_alignTop="@id/bub_left"
android:layout_alignBottom="@id/bub_left"
And the result is like this:
Please help, Thanks in advance.
Solution
Please replace your activity with this code. And check the result.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bub_right"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:weightSum="3" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Left Side layout" />
</LinearLayout>
<LinearLayout
android:layout_width="50dp"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:weightSum="1" >
<ImageView
android:id="@+id/bub_up"
android:layout_width="30dip"
android:layout_height="wrap_content"
android:gravity="center"
android:src="@drawable/ic_launcher"
android:textSize="15dp" />
<TextView
android:id="@+id/bub_score"
android:layout_width="30dip"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="123" />
<ImageView
android:id="@+id/bub_down"
android:layout_width="30dip"
android:layout_height="wrap_content"
android:gravity="center"
android:src="@drawable/ic_launcher" />
</LinearLayout>
Answered By - Rishi Paul
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.