bringToFront() is the right way, but, NOTE, you must call the bringToFront() and invalidate() methods at the highest level (under the root view), for example:
Your view hierarchy:
-RelativeLayout |--LinearLayout1 |------Button1 |------Button2 |------Button3 |--ImageView |--LinearLayout2 |------Button4 |------Button5 |------Button6
So, when you animate your buttons (1-> 6), your buttons will be at the bottom (below) of the ImageView . To cast it (at the top) of the ImageView , you must call the bringToFront() and invalidate() LinearLayout on your LinearLayout s. Then it will work :) ** NOTE. Remember to set android:clipChildren="false" for the root layout or animated view gradparent_layout. Let's take a look at my real code:
.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>
Some code in .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 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);
Glitch!
Justin May 15 '14 at 4:00 a.m. 2014-05-15 04:00
source share