【发布时间】:2014-05-22 12:22:01
【问题描述】:
我有一个RelativeLayout,左边是ImageView 和TextView,右边是ImageView 和TextView。
但它们与 ImageView 没有很好地对齐。我希望它垂直居中对齐文本视图旁边的图像
现在是这样的:
我使用的 RelativeLayout 是这样的:
问题
如何使TextView 与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>
【问题讨论】:
-
“对齐良好”是什么意思?你到底要达到什么目标?
-
你试过
android:layout_centerVertical="true"吗? -
我假设您希望图像与文本的基线对齐(而不是与 textView 的底部对齐)。
android:layout_alignBaseline可能就是你要找的。span> -
@FarhadFaghihi 我正在尝试将 TextView 垂直居中对齐到它旁边的图像
-
@birdy :您是否为 ImageViews 和 TextViews 都尝试过
android:layout_centerVertical="true"?他们都需要具有该属性。