让imageview出现在Gallery上方
我有一个图库小部件和 2 个图像视图,一个位于屏幕左侧,一个位于屏幕右侧。我希望 imageview 和 gallery 保持在同一条线上,但如果存在重叠,imageview 的 z-index 应该高于 gallery 的 z-index。
问题是图像视图出现在图库项目下方。我查看了 android 文档,但找不到解决方案。我的 XML 文件如下(由于某种原因,开始根相对布局的开始和结束标记未显示):
<ImageView
android:id="@+id/greenarrow_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/green_arrow_right"
android:layout_alignParentRight="true"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
/>
<ImageView
android:id="@+id/greenarrow_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/green_arrow_left"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dip"
android:layout_marginTop="10dip"
/>
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:spacing="3dip"
/>
<!-- more elements here -->
I have a Gallery widget and 2 imageviews, one on the left of the screen and one on the right. I want the imageview and gallery to stay on the same line, but if there is an overlap, the imageview's z-index should be higher then the gallery's.
The problem is the imageview appears underneath the gallery item. I've had a look in the android doc, but can't find the solution. My XML file is below (For some reason, the opening Root relative layout's opening and closing tag isn't showing up):
<ImageView
android:id="@+id/greenarrow_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/green_arrow_right"
android:layout_alignParentRight="true"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
/>
<ImageView
android:id="@+id/greenarrow_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/green_arrow_left"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dip"
android:layout_marginTop="10dip"
/>
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:spacing="3dip"
/>
<!-- more elements here -->
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
RelativeLayout
的最后一个子级将位于顶部。如果您的布局如上所示,则意味着Gallery
将位于第二个ImageView
之上。更改 XML 和RelativeLayout
规则,使第二个ImageView
出现在 XML 中的Gallery
之后。The last child of the
RelativeLayout
will be on top. If your layout is as depicted above, that means theGallery
will be on top of the secondImageView
. Change your XML and theRelativeLayout
rules to make the secondImageView
appear after theGallery
in the XML.您尝试过 ViewParent.BringChildToFront(myImageView) 吗?
Did you try
ViewParent.BringChildToFront(myImageView)
?