I am trying to use a TranslateAnimation to slide controls in and out
of screen as available.  The top level layout is a RelativeLayout as I
want to display items on each side of screen.

The controls are in a ViewGroup with other things I'm trying to slide
up to make room for the controls.  I'm animating the ViewGroup and
then changing the visibility of the controls.

To display the controls, I set the controls to visible and then
animate the ViewGroup sliding up; everything works fine.

When I hide the controls, I animate the ViewGroup down (not fully off
screen as the remainder needs to stay visible) and in the
onAnimationEnd() callback I set the visibility of the controls to
GONE.  This causes the ViewGroup to compute layout, etc. which causes
the view to flicker.

I've reproduced with the simplest parallel of two text lines and
hiding/showing the bottom one.  Can anyone tell me what I'm missing.
There has to be a way to get the layout to not redraw or to cache such
that it doesn't flicker.

XML for layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android";
        android:layout_height="fill_parent"
android:layout_width="fill_parent"
        >
        <Button
                android:id="@+id/button2"
                android:text="flip"
                android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
                android:layout_width="wrap_content"
android:layout_height="wrap_content"
        />

        <LinearLayout
                android:id="@+id/textGroup"
                android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
                android:layout_height="wrap_content"
android:layout_width="wrap_content"
                android:orientation="vertical"
                android:gravity="center_horizontal"
        >
                <TextView
                        android:id="@+id/text1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center_horizontal"
                        android:textSize="26sp"
                        android:text="hello world"/>
                <TextView
                        android:id="@+id/text2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center_horizontal"
                        android:textSize="26sp"
                        android:text="morons should all unite"/>
        </LinearLayout>
</RelativeLayout>

Source code I'm running when Flip is clicked:
    public void showNext() {
        Animation       anim;
        if (mOpen) {    // We are now opening the buttons
                anim = new TranslateAnimation(
                                Animation.RELATIVE_TO_SELF, 0.0f,
                                Animation.RELATIVE_TO_SELF, 0.0f,
                                Animation.RELATIVE_TO_SELF, 0.5f,
                                Animation.RELATIVE_TO_SELF, 0.0f  );
        } else {                // We are closing the buttons
                anim = new TranslateAnimation(
                                Animation.RELATIVE_TO_SELF, 0.0f,
                                Animation.RELATIVE_TO_SELF, 0.0f,
                                Animation.RELATIVE_TO_SELF, 0.0f,
                                Animation.RELATIVE_TO_SELF, 0.5f  );
        } // else
        anim.setDuration(500);
        anim.setAnimationListener(this);

        mTextView2.setVisibility(View.VISIBLE);
        mTextGroup.startAnimation(anim);
    } // showNext

        public void onAnimationEnd(Animation animation) {
                if (!mOpen)
                        mTextView2.setVisibility(View.GONE);
        } // onAnimationEnd

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to