views:

681

answers:

0

I have a fairly complex layout. I use a relative layout as the root and then inside of it I have a few table views and some further nesting. When I animate an imageview between these layouts my image clips. I have a background on the parent layout and the animation looks like it's going under it. I have set android:clipChildren="false" and android:clipToPadding="false" on all of the layouts. I've also set anim.setZAdjustment(Animation.ZORDER_TOP); on all of my animations. What am I doing wrong?

EDIT: I've found at least 2 bugs so far. android:background= with a hex color causes major animation issues. Table layouts also seem to have a regoin under them that causes clipping. I am also seeing the same thing with framelayouts. I'll add an answer once I actually get my stuff working the way I want it to. I have a feeling using only linear layouts is the solution.

Here is some sample code that produces the issue. If you remove the two child relative layouts then the animation completes as expected.


Java:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ImageView imageViewtop = (ImageView) findViewById(R.id.ImageView01);
    imageViewtop.setOnClickListener(btnCardListener);
}

private OnClickListener btnCardListener = new OnClickListener() {
    public void onClick(View v) {

        ImageView ImageView03 = (ImageView) findViewById(R.id.ImageView03);
        ImageView ImageView05 = (ImageView) findViewById(R.id.ImageView05);

        int[] playLoc = { 0, 0 };
        int[] botLoc = { 0, 0 };
        ImageView05.getLocationOnScreen(playLoc);
        ImageView03.getLocationOnScreen(botLoc);
        int xMove = playLoc[0] - botLoc[0];
        int yMove = playLoc[1] - botLoc[1];

        AnimationSet animSet = new AnimationSet(true);

        RotateAnimation ranim = new RotateAnimation(0f, 180f,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f); // , 200, 200); //
                                                    // canvas.getWidth()
        // 2, canvas.getHeight() / 2);
        ranim.setDuration(400);
        ranim.setInterpolator(new DecelerateInterpolator());

        TranslateAnimation transAnim = new TranslateAnimation(
                Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, xMove, // +80.0f,
                Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, yMove // -100.0f
        );
        transAnim.setInterpolator(new DecelerateInterpolator()); // AccelerateInterpolator
                                                                    // ,
                                                                    // LinearInterpolator
        transAnim.setZAdjustment(Animation.ZORDER_TOP);
        transAnim.setAnimationListener(new AnimationListener() {
            public void onAnimationStart(Animation animation) {
            }

            public void onAnimationEnd(Animation animation) {
                ImageView ImageView03 = (ImageView) findViewById(R.id.ImageView03);
                ImageView ImageView05 = (ImageView) findViewById(R.id.ImageView05);

                ImageView05.setVisibility(View.VISIBLE);
                ImageView03.setVisibility(View.INVISIBLE);
            }

            public void onAnimationRepeat(Animation animation) {
            }
        });
        transAnim.setDuration(1000);

        // Order matters...
        animSet.addAnimation(ranim);
        animSet.addAnimation(transAnim);

        ImageView03.startAnimation(animSet);
    }
};

XML:

<RelativeLayout android:id="@+id/relativeParentLayout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:clipToPadding="false">
    <RelativeLayout android:id="@+id/relativeParentLayout1"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="150dip" android:background="#440000"
        android:layout_alignParentTop="true" android:clipChildren="false"
        android:clipToPadding="false">
        <ImageView android:layout_height="wrap_content" android:id="@+id/ImageView01"
            android:layout_width="wrap_content" android:src="@drawable/card_back"
            android:layout_weight="0" android:layout_alignParentTop="true" />


        <ImageView android:layout_height="wrap_content" android:id="@+id/ImageView03"
            android:layout_width="wrap_content" android:src="@drawable/card_back"
            android:layout_weight="0" android:layout_gravity="center_vertical"
            android:layout_alignParentRight="true" />
    </RelativeLayout>
    <RelativeLayout android:id="@+id/relativeParentLayout2"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="150dip" android:background="#000044"
        android:layout_alignParentBottom="true" android:clipChildren="false"
        android:clipToPadding="false">

        <ImageView android:layout_height="wrap_content"
            android:layout_below="@+id/LinearLayout01" android:id="@+id/ImageView05"
            android:layout_width="wrap_content" android:src="@drawable/card_back"
            android:layout_weight="0" android:layout_alignParentBottom="true" />
    </RelativeLayout>
</RelativeLayout>