我创建了一个滑动抽屉动画,可以同时打开/关闭和增大/缩小。我正在使用ValueAnimator并且在AnimatorUpdateListener内部我操纵视图的边距来增加或减少(增大/缩小)它的大小。同时,ValueAnimator正在处理开启和关闭。对于Galaxy Mega 2手机,这款动画非常不稳定;根本不顺利。所有其他手机,无论新旧,似乎都运行良好。有什么方法可以解决这个问题吗?
// close drawer
ValueAnimator animator = ValueAnimator.ofInt(0, 100);
animator.setInterpolator(new AccelerateInterpolator());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float ratio = ((Integer) animation.getAnimatedValue() / 100);
// moves the drawer to the left and reduces its size by changing its margins
mDrawerParams.setMargins((int) (mLeftMargin * ratio), (Integer) animation.getAnimatedValue(),
0, (Integer) animation.getAnimatedValue());
rlDrawer.setLayoutParams(mDrawerParams);
}
以下是我打开抽屉的方式
// open drawer
ValueAnimator animator = ValueAnimator.ofInt(100, 0);
animator.setInterpolator(new AccelerateInterpolator());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float ratio = ((Integer) animation.getAnimatedValue() / 100);
// moves the drawer to the right and increases its size by changing its margins
mDrawerParams.setMargins((int) (mLeftMargin * ratio), (Integer) animation.getAnimatedValue(),
0, (Integer) animation.getAnimatedValue());
rlDrawer.setLayoutParams(mDrawerParams);
}
答案 0 :(得分:2)
如果您更改了layoutParams,则在名为onRequesLayout的View上,存在滞后。您需要更改属性。更改translation_x,scale_x,scale_y属性。例如:
Animator animator = ObjectAnimator.ofFloat(drawerLayout, View.TRANSLATION_X, 0, (float) );