I have a RelativeLayout
with ImageView
and TextView
on the left and ImageView
and TextView
on the right.
but they are not aligning well with the ImageView. I want it to align vertically center to the image next to the text view
This is how it looks at the moment:
The RelativeLayout I'm using is this:
Question
How can I make the TextView
align well with the ImageView
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/leftIcon"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/trash" />
<TextView
android:id="@+id/tv1"
android:layout_toRightOf="@+id/leftIcon"
android:layout_toLeftOf="@+id/iv2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14dp"
android:text="some text 1"
android:layout_marginLeft="5dp"
android:textColor="#000000"
android:textStyle="bold"/>
<ImageView
android:id="@+id/iv2"
android:layout_toLeftOf="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/trash" />
<TextView
android:layout_alignParentRight="true"
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dp"
android:textColor="#000000"
android:text="some text 2"
android:textStyle="bold"
android:layout_marginLeft="5dp"
android:layout_marginRight="25dp" />
</RelativeLayout>
hi try this code i think it will help you :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<ImageView
android:id="@+id/leftIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_menu_delete" />
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="some text 1"
android:textColor="#ffffff"
android:textSize="14dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="@+id/iv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_menu_delete" />
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="25dp"
android:text="some text 2"
android:textColor="#ffffff"
android:textSize="14dp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
// Try this way,hope this will help you to solve your problem...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="@+id/leftIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:adjustViewBounds="true"/>
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:text="some text 1"
android:layout_marginLeft="5dp"
android:textColor="#000000"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|right">
<ImageView
android:id="@+id/iv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:adjustViewBounds="true"/>
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#000000"
android:text="some text 2"
android:textStyle="bold"
android:layout_marginLeft="5dp"
android:layout_marginRight="25dp" />
</LinearLayout>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/leftIcon"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/iv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/tv2"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv2"
android:layout_toRightOf="@+id/leftIcon"
android:text="some text 1"
android:textColor="#000000"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="26dp"
android:text="some text 2"
android:textColor="#000000"
android:textSize="14dp"
android:textStyle="bold" />
</RelativeLayout>
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.