Android ImageView隐藏在按钮后面的想法

Android ImageView隐藏在按钮后面的想法,android,button,imageview,Android,Button,Imageview,我有一个ImageView在屏幕上移动,但一旦它到达一个按钮,它就会在它后面移动,ImageView就会隐藏起来。它们在不同的布局上。我已经尝试将ImageView和布局放在前面,并使按钮既不可见又透明(setAlpha(0))。不知道什么代码会在这里有帮助,但只要问一下,我会很高兴地张贴任何需要的 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://s

我有一个ImageView在屏幕上移动,但一旦它到达一个按钮,它就会在它后面移动,ImageView就会隐藏起来。它们在不同的布局上。我已经尝试将ImageView和布局放在前面,并使按钮既不可见又透明(setAlpha(0))。不知道什么代码会在这里有帮助,但只要问一下,我会很高兴地张贴任何需要的

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"  tools:context=".MainActivity"

android:id="@+id/relativeLayout1">
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/friendly1"


    />
<Button

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/choice1"
    android:layout_weight="5"
    android:clickable="true"
    android:id="@+id/btnRow1"
    android:alpha="0"
    android:visibility="invisible"
    android:onClick="onClickRow1"/>
</LinearLayout>
</RelativeLayout>

可以从父视图中删除视图,然后在指定索引处重新添加视图。这将允许您控制哪些视图位于其他视图的前面/后面

ViewGroup parent=(ViewGroup)viewToRemove.getParent();
parent.removeView(viewToRemove);
parent.addView(viewToRemove,index);
其中'index'是要放置视图的索引的int值。索引较高的视图显示在索引较低的视图上方


额外提示:如果您愿意,可以对所有要添加的视图使用相同的索引,您首先添加的视图将显示在您接下来添加的视图的下方(因为视图组的工作方式类似于ArrayList)。

发布片段的xml/活动请创建一个。上面的布局代码没有意义-您有一个关闭但没有打开的窗口??
 friendly1 = (ImageView) findViewById(R.id.friendly1);
 friendly1.bringToFront();

RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.relativeLayout1);
mainLayout.bringToFront();