首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >layout_toRightOf能用而layout_toLeftOf不能用,该如何解决?

layout_toRightOf能用而layout_toLeftOf不能用,该如何解决?
EN

Stack Overflow用户
提问于 2012-02-09 17:08:04
回答 3查看 14.4K关注 0票数 2

我有一个简单的相对布局--一个ImageView ( iv1 )和一个TextView (tv1)在iv1的左边。不幸的是,我看不到tv1。更重要的是,即使是hierarchyViewer也不能帮我找到它。

代码语言:javascript
复制
<?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工作?

EN

Stack Overflow用户

发布于 2016-11-23 22:49:47

在我的例子中(不是在这个布局中),问题出在RelativeLayout的android:layout_width中。当它是wrap_contentmatch_parent时,布局变得分散。例如,当我将其设置为300dp时,一切都很好。

票数 0
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9207969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档