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);
}
如果誰的人有一個解決方案可以寫一個很好的答案,我將不勝感激! 提前致謝:)