首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在RelativeLayout中使用layout_above

在RelativeLayout中使用layout_above
EN

Stack Overflow用户
提问于 2011-05-12 05:21:36
回答 3查看 72.4K关注 0票数 21

有人能给我解释一下为什么ImageView没有出现在LinearLayout上面吗?

代码语言:javascript
复制
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:id="@+id/rev_main"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <!-- some stuff in here -->
    </LinearLayout>
    <ImageView
        android:id="@+id/rev_arrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/arrow"
        android:layout_above="@id/rev_main"
        />
</RelativeLayout>

我还是不明白。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-05-12 05:48:06

当您指定相对于另一个布局的对齐方式时,会发生这种情况。我找到的解决方案是走另一个方向。

与其告诉ImageView在LinearLayout之上,不如告诉LinearLayout在ImageView之下。

代码语言:javascript
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:id="@+id/rev_main"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/rev_arrow">
        <!-- some stuff in here -->
    </LinearLayout>
    <ImageView
        android:id="@+id/rev_arrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/arrow"
        />
</RelativeLayout>
票数 27
EN

Stack Overflow用户

发布于 2011-05-12 05:40:17

以下内容应该适用于您:

代码语言:javascript
复制
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/rev_arrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/arrow"
        android:layout_alignParentTop="true"
        />
    <LinearLayout
        android:id="@+id/rev_main"
        android:layout_width="fill_parent"
        android:layout_below="@id/rev_arrow"
        android:layout_height="wrap_content">
        <!-- some stuff in here -->
    </LinearLayout>
</RelativeLayout>
票数 7
EN

Stack Overflow用户

发布于 2012-11-17 21:09:28

我在创建自定义optionsMenu时遇到了类似的问题。设置视图z顺序的最简单方法是以编程方式完成。如果您有时想要切换顺序,您可以轻松地调用:

代码语言:javascript
复制
    ImageView yourImageView = (ImageView)findViewById(R.id.rev_arrow);
    yourImageView.bringToFront();

我不知道它是否适合你的应用程序,但在我的例子中,它工作得很好。如果你需要更多的代码,请告诉我。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5970773

复制
相关文章

相似问题

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