一、布局文件相关定义
<?xml version="1.0" encoding="utf-8"?>
<!-- xmlns:android="http://schemas.android.com/apk/res/android" -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iv1"
android:src="@drawable/baiyang"
android:layout_width="100dp"
android:layout_height="150dp"
android:onClick="iv1click"/>
<ImageView
android:id="@+id/iv2"
android:src="@drawable/jinniu"
android:layout_width="100dp"
android:layout_height="150dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="50dp"
android:onClick="iv2click"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iv3"
android:src="@drawable/baiyang"
android:layout_width="100dp"
android:layout_height="150dp"
android:onClick="iv3click"/>
<ImageView
android:id="@+id/iv4"
android:src="@drawable/jinniu"
android:layout_width="100dp"
android:layout_height="150dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="50dp"
android:onClick="iv4click"/>
</RelativeLayout>
</LinearLayout>
二、相关java代码(仅事件方法)
public void iv1click(View view)
{
ViewGroup vg = (ViewGroup)view.getParent();
int index = vg.indexOfChild(view);
vg.bringChildToFront(vg.getChildAt(index));
vg.invalidate();
}
public void iv2click(View view)
{
ViewGroup vg = (ViewGroup)view.getParent();
int index = vg.indexOfChild(view);
vg.bringChildToFront(vg.getChildAt(index));
vg.invalidate();
}
public void iv3click(View view)
{
ViewGroup vg = (ViewGroup)view.getParent();
int index = vg.indexOfChild(view);
vg.bringChildToFront(vg.getChildAt(index));
vg.invalidate();
}
public void iv4click(View view)
{
ViewGroup vg = (ViewGroup)view.getParent();
int index = vg.indexOfChild(view);
vg.bringChildToFront(vg.getChildAt(index));
vg.invalidate();
}