bringToFront()เป็นวิธีที่ถูกต้อง แต่โปรดทราบว่าคุณต้องเรียกใช้bringToFront()และinvalidate()วิธีการในมุมมองระดับสูงสุด (ภายใต้มุมมองรูทของคุณ) เช่น:
ลำดับชั้นของมุมมองของคุณคือ:
-RelativeLayout
|--LinearLayout1
|------Button1
|------Button2
|------Button3
|--ImageView
|--LinearLayout2
|------Button4
|------Button5
|------Button6
ดังนั้นเมื่อคุณเคลื่อนไหวกลับปุ่มของคุณ (1-> 6), ปุ่มของคุณจะอยู่ภายใต้ (ด้านล่าง) ImageViewเพื่อนำมันไป (ด้านบน) ImageViewคุณต้องเรียกbringToFront()และinvalidate()วิธีการในLinearLayouts จากนั้นมันจะทำงาน :) ** หมายเหตุ: อย่าลืมตั้งค่าandroid:clipChildren="false"สำหรับเค้าโครงรูทของคุณหรือ gradparent_layout ของมุมมองภาพเคลื่อนไหว ลองดูรหัสจริงของฉัน:
.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:hw="http://schemas.android.com/apk/res-auto"
    android:id="@+id/layout_parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/common_theme_color"
    android:orientation="vertical" >
    <com.binh.helloworld.customviews.HWActionBar
        android:id="@+id/action_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/dimen_actionbar_height"
        android:layout_alignParentTop="true"
        hw:titleText="@string/app_name" >
    </com.binh.helloworld.customviews.HWActionBar>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/action_bar"
        android:clipChildren="false" >
        <LinearLayout
            android:id="@+id/layout_top"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:gravity="center_horizontal"
            android:orientation="horizontal" >
        </LinearLayout>
        <ImageView
            android:id="@+id/imgv_main"
            android:layout_width="@dimen/common_imgv_height"
            android:layout_height="@dimen/common_imgv_height"
            android:layout_centerInParent="true"
            android:contentDescription="@string/app_name"
            android:src="@drawable/ic_launcher" />
        <LinearLayout
            android:id="@+id/layout_bottom"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:gravity="center_horizontal"
            android:orientation="horizontal" >
        </LinearLayout>
    </RelativeLayout>
</RelativeLayout>
บางรหัสใน. java
private LinearLayout layoutTop, layoutBottom;
...
layoutTop = (LinearLayout) rootView.findViewById(R.id.layout_top);
layoutBottom = (LinearLayout) rootView.findViewById(R.id.layout_bottom);
...
//when animate back
//dragedView is my layoutTop's child view (i added programmatically) (like buttons in above example) 
dragedView.setVisibility(View.GONE);
layoutTop.bringToFront();
layoutTop.invalidate();
dragedView.startAnimation(animation); // TranslateAnimation
dragedView.setVisibility(View.VISIBLE);
กลุค!
               
              
RelativeLayoutมีมุมมอง "ด้านบน" ปรากฏเป็นอันดับสุดท้ายใน XML ดูstackoverflow.com/a/31340762/1121497