【发布时间】:2016-11-23 22:49:47
【问题描述】:
我有简单的相对布局 - 一个 ImageView (iv1) 和一个 TextView (tv1) 在 iv1 的左侧。不幸的是,我没有看到tv1。更何况连hierarchyViewer都帮我找不到了。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:background="@android:color/white"
>
<ImageView
android:id="@+id/iv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/tv1"
android:layout_toLeftOf="@+id/iv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</RelativeLayout>
看起来是这样的:
但是,如果我将 android:layout_toLeftOf="@+id/iv1" 更改为 android:layout_toRightOf="@+id/iv1",我的文本视图将位于图像视图的右侧。似乎 toRightOf 有效,而 toLeftOf 无效。 如下所示:
这是怎么回事?如何让 layout_toLeftOf 工作?
【问题讨论】: