之前一直用的是向左平移和向右平移的切换动画,看到别的APP那个抽屉效果,自己也弄了一个!感谢给我提供帮助的大神们!
将退出动画的参数设置为0时,进入动画则设置为向左平移,就实现了抽屉效果!
进入的动画:push_left_in.xml
1
2
3
4
5
6
7
8
9
10
|
<?xml version= "1.0"
encoding= "utf-8" ?>
<translate
android:duration= "300"
android:fromXDelta= "100.0%"
android:interpolator= "@android:anim/accelerate_interpolator"
android:toXDelta= "0.0%"
/>
</set> |
退出的动画:push_left_out.xml
1
2
3
4
5
6
7
8
9
10
11
|
<?xml version= "1.0"
encoding= "utf-8" ?>
<translate
android:duration= "300"
android:fromXDelta= "0"
android:interpolator= "@android:anim/decelerate_interpolator"
android:toXDelta= "0"
>
</translate>
</set> |
java代码:
1
2
3
4
|
int
version = Integer.valueOf(android.os.Build.VERSION.SDK);
if
(version >= 5 ) {
overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
}
|
还有一个是向右移出的切换:
退出动画:push_right_out.xml
1
2
3
4
5
6
7
8
9
10
|
<?xml version= "1.0"
encoding= "utf-8" ?>
<translate
android:duration= "300"
android:fromXDelta= "0"
android:interpolator= "@android:anim/accelerate_interpolator"
android:toXDelta= "100.0%"
/>
</set> |
java代码:
把进来的动画设置为0:
1
2
3
4
|
int
version = Integer.valueOf(android.os.Build.VERSION.SDK);
if
(version >= 5 ) {
overridePendingTransition( 0 , R.anim.push_right_out);
}
|
下面是图片效果: