I have found several guides on how to get a 3D animation to flip views in ViewFlipper. They all use Camera and rotation to achieve the effect. I used this: http://code.google.com/p/android-3d-flip-view-transition/ - wrapper to achieve the results - and everything works just fine. That is, as far as the visual flipping is concerned.
What doesn't work though is the button afer the flip is completed. It feels as if all the onClick events are either not received or are simply ignored after the flipping is completed. Here's my very basic example.
XML:
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/selector_flipper">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/playing_field"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Flip"
android:onClick="flipView" />
</LinearLayout>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tag_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"/>
</ViewFlipper>
Activity:
public class SelectorActivity extends Activity {
private ViewFlipper flipper;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.selector);
flipper = (ViewFlipper)this.findViewById(R.id.selector_flipper);
}
/**
* @see android.app.Activity#onKeyDown(int, android.view.KeyEvent)
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && tagList.getVisibility() == View.VISIBLE)
flipView(null);
else
return super.onKeyDown(keyCode, event);
}
public void flipView(View v) {
AnimationFactory.flipTransition(flipper, FlipDirection.RIGHT_LEFT);
}
}
When the activity is created, I can click the "Flip" button - and the view flips as I want it to. I can then press the "back" button on the handset - and it flips back, just as I want it to. However now I can't click the button any more - all the clicks are simply ignored.
Can anybody help me get to the bottom of this problem? Much appreciated!
P.S. I tried other wrappers and even coding the same animation myself - but the result has always been the same! Clicks do not work after the flip!
thanks for using my 3D view flip animation.
The issue is a bug in Android in the way ViewGroup
traverses who gets focus. I tried a number of fixes (some worked and some didn't, but none were very elegant). But at the end, using AnimationSet
instead of Animation
did the trick. I've tried the fix on your code (that you emailed me) but also on a more complex code. The displayed view after a transition gets the touch focus.
So, the latest update to android-3d-flip-view-transition in the googlecode project has the fix. Or, you can directly navigate to the revision by clicking here.
Thanks and please mark this question as answered if you are satisfied with the fix.