[英]Bring view to the front prprogrammaticly
我正在使用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);
}
如果有解决方案的人可以写一个好的答案,我将不胜感激! 在此先感谢:)
您可以尝试在适当的视图上调用View#bringToFront() 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.