layout_toRightOf的作品和layout_toLeftOf没有,怎么解决?

Eug*_*mak 2 android android-layout

我有简单的相对布局 - 一个ImageView(iv1)和一个iv1左边的TextView(tv1).不幸的是,我看不到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>
Run Code Online (Sandbox Code Playgroud)

它看起来像这样:

在此输入图像描述

但是,如果我将android:layout_toLeftOf ="@ + id/iv1"改为android:layout_toRightOf ="@ + id/iv1",我的文本视图将定位在图像视图的右侧.看起来像是右边的作品,而左边的作品却没有.在这里看起来如何:

在此输入图像描述

有什么事?如何使layout_toLeftOf工作?

ezc*_*ing 5

更改:

<TextView
    android:id="@+id/tv1"
    android:layout_toLeftOf="@+id/+iv1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />
Run Code Online (Sandbox Code Playgroud)

至:

<TextView
    android:id="@+id/tv1"
    android:layout_toLeftOf="@id/iv1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />
Run Code Online (Sandbox Code Playgroud)

您在TextView中的toLeftOf中使用@ + id/iv1而不是@ id/iv1.您还应该将imageview提供给视图中的特定位置.尝试对齐它:layout_parentTop = true