有人能给我解释一下为什么ImageView没有出现在LinearLayout上面吗?
<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>
我还是不明白。
发布于 2011-05-12 05:48:06
当您指定相对于另一个布局的对齐方式时,会发生这种情况。我找到的解决方案是走另一个方向。
与其告诉ImageView在LinearLayout之上,不如告诉LinearLayout在ImageView之下。
<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>
发布于 2011-05-12 05:40:17
以下内容应该适用于您:
<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>
发布于 2012-11-17 21:09:28
我在创建自定义optionsMenu时遇到了类似的问题。设置视图z顺序的最简单方法是以编程方式完成。如果您有时想要切换顺序,您可以轻松地调用:
ImageView yourImageView = (ImageView)findViewById(R.id.rev_arrow);
yourImageView.bringToFront();
我不知道它是否适合你的应用程序,但在我的例子中,它工作得很好。如果你需要更多的代码,请告诉我。
https://stackoverflow.com/questions/5970773
复制相似问题