0
我正在使用frameLayout,并试图在单击imageButton时以编程方式在上显示另一个视图。我使用框架布局,因为我被告知它允许您将视图放在彼此之上。然而,单击按钮时,imageView会在另一个视图背后消失,而不是在前面。 这里是我的布局 - “洞”是imageButton,每当它点击时,imageView“goola”需要移动它。将视图带到前面编程式
<FrameLayout 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="${relativePackage}.${activityClass}" >
<ImageButton
android:id="@+id/hole"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:background="@android:color/transparent"
android:src="@drawable/home0" />
<ImageView
android:id="@+id/goola"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="@drawable/goola" />
这里是JAVA(的onClick方法)
@Override
public void onClick(View v)
{
ImageButton b=(ImageButton)v;
int[] location = new int[2];
b.getLocationOnScreen(location);
float startX = location[0];
float startY = location[1];
goola.setX(startX);
goola.setY(startY);
}
如果谁的人有一个解决方案可以写一个很好的答案,我将不胜感激! 提前致谢:)