我想在android中将按钮(子视图)带到前面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20097526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
I want to bring button(subview) to front in android
提问by immodi
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/topHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<!-- Header aligned to top -->
<!-- <include layout="@layout/header_layout" /> -->
<!-- Footer aligned to bottom -->
<!-- <include layout="@layout/footer_layout" /> -->
<!-- Content below header and above footer -->
<!-- <include layout="@layout/intermediate_layout" /> -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ImageView
android:id="@+id/imgLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/header" />
</RelativeLayout>
</RelativeLayout>
I make layout xml, in which I put one button in center.And I want that button to front always. I adding some textview, imageview etc dynamically on this layout and that one centerised button should be bring front. This is possible in ios and i want in android.Any suggestion for this thoughts? I have above topHeaderlayout.xmlIn this xml, I dynamically adds view.And one button should be front of view.
我制作布局 xml,在其中我将一个按钮放在中间。我希望该按钮始终位于前面。我在这个布局上动态添加了一些 textview、imageview 等,并且一个居中的按钮应该放在前面。这在 ios 中是可能的,我想要在 android.Any 对此想法的建议?我有上面的topHeaderlayout.xml在这个xml中,我动态添加了view。并且一个按钮应该在view的前面。
回答by artemiygrn
You may use bringToFrontmethod (http://developer.android.com/reference/android/view/View.html). Also please read this — Defining Z order of views of RelativeLayout in Android. I think this should help.
您可以使用becomeToFront方法(http://developer.android.com/reference/android/view/View.html)。另请阅读此 —在 Android 中定义 RelativeLayout 视图的 Z 顺序。我认为这应该有所帮助。
回答by John Ashmore
To both summarize and yet clarify:
总结并澄清:
yourView.bringToFront();