我使用GestureDetector.SimpleOnGestureListener中的onFling方法来切换activity内部的片段。
一切正常,但没有任何过渡效果。当我抛出时,新的碎片会立即出现。
我想有类似SwipeListView的动画效果。有什么简单的方法可以做到吗?
发布于 2014-09-23 22:05:01
(1)创建动画资源如下所示
<?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)在onFling事件时调用fragment transition (我猜您已经这样做了..) (3)使用setCustomAnimations方法显示定义在(1)资源中的动画。(假设资源名称为slideLeft.xml和slideRight.xml)
fragmentManager.beginTransaction()
.setCustomAnimations(R.anim.slideLeft, R.anim.slideRight)
.replace(R.id.container, myFragment)
.commit();注意,setCustomAnimations方法调用应该在'replace‘方法调用的上面,并且setCustomAnimations方法的参数将是动画资源的名称
并检查此答案https://stackoverflow.com/a/19769903,以获得更完整的片段动画示例。
https://stackoverflow.com/questions/25020307
复制相似问题