我有一个简单的相对布局--一个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工作?
发布于 2016-11-23 22:49:47
在我的例子中(不是在这个布局中),问题出在RelativeLayout的android:layout_width中。当它是wrap_content或match_parent时,布局变得分散。例如,当我将其设置为300dp时,一切都很好。
https://stackoverflow.com/questions/9207969
复制相似问题