android - 从上到下淡入/淡出视图,反之亦然,而无需使用 Scale 平移或缩小视图
问题描述
我正在尝试实现从上到下淡化视图的动画,反之亦然。视图在消失时应保持其比例和位置。出于这个原因,我不能使用平移或比例(比例会缩小视图。
任何人都可以帮助我实现这一目标吗?
解决方案
也许overridePendingTransition会有所帮助?
Intent newActivity = new Intent(getApplicationContext(), activity.class);
startActivity(newActivity);
this.overridePendingTransition(R.anim.swipe_left_enter, R.anim.swipe_left_exit);
动画滑动可以是这样的:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="0.0"
android:fromYScale="1.0"
android:pivotX="100%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0"
android:duration="100"
android:fillAfter="true"/>
</set>
这是一个滑动示例,但也可以用作淡入淡出动画。
PS我忘了提到你应该实施
class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent event1, MotionEvent event2,
float velocityX, float velocityY) {
// your code here
}
}