2

I'm using onFling method from GestureDetector.SimpleOnGestureListener to switch fragments inside activity.

Everything works fine but there is no any transition effect. New fragment appears instantly when I fling.

I would like to have animation effect similar to SwipeListView. Is there any simple way to do that?

user3199693
  • 128
  • 4
  • 12
  • onFling is just a notification that you performed a fling gesture, what you need is to start an animation that makes the real effect – pskink Jul 29 '14 at 17:37

1 Answers1

-1

(1) Create animation resouces like this

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <objectAnimator
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="500"
        android:propertyName="x"
        android:valueFrom="1000"
        android:valueTo="0"
        android:valueType="floatType" />

</set>

(2) Call fragment transition when onFling event (I guess you already do this..) (3) Use setCustomAnimations method for show animation that defines in (1) resources. (Assume that resource name was slideLeft.xml and slideRight.xml)

fragmentManager.beginTransaction()
            .setCustomAnimations(R.anim.slideLeft, R.anim.slideRight)
            .replace(R.id.container, myFragment)
            .commit();

Note that setCustomAnimations method calling should be above of 'replace' method calling and parameter of setCustomAnimations method will be name of animation resou

And also check this answer https://stackoverflow.com/a/19769903 to more fully example for fragment animation.

Community
  • 1
  • 1
papercut
  • 59
  • 2