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
--

Hi all,
I am relatively new to android development. I am attempting to
build an app that will have to make asynchronous server calls. Is
there a recommended way to do this in android? I haven't found too
much information by googling. Thank you, Craig
--