I use the following class to play a animation in my app. This works well when the view tree is simple. While, it stuck when I use it in a complex fragment (i.e. the view maybe overdrawed). Is there any way to optimize the efficiency ? I have heard about use surface view and control the redraw district of my Activity, but I need some examples. Thanks a lot.

我使用以下类在我的应用程序中播放动画。当视图树很简单时,这很有效。然而,当我在一个复杂的片段中使用它时它会卡住(即视图可能被过度绘制)。有没有办法优化效率?我听说过使用表面视图并控制我的Activity的重绘区,但我需要一些例子。非常感谢。

This is my code

这是我的代码

private ValueAnimator performAnim(final View target1, final int start, final int end, final int duration) {
    ValueAnimator valueAnimator = ValueAnimator.ofInt(0, duration);

    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        private IntEvaluator mEvaluator = new IntEvaluator();

        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            Integer currentValue = (Integer) animator.getAnimatedValue();
            float rate = currentValue/((float)duration);
            Log.d("zcc", "currentValue" + currentValue);
            int value = mEvaluator.evaluate(rate, start, end);
            Log.d("zcc", "+" + value + "start : "+ start + " end : "+ end + " duration : " + duration);
            ((LayoutParams) target1.getLayoutParams()).leftMargin = value;
            target1.requestLayout();
        }
    });

    valueAnimator.setDuration(duration);
    return valueAnimator;
}

1 个解决方案

#1


0

requestLayout() method will measure and layout the views. Thus, the efficiency is quite low. invalid() method, which I use now, will only redraw the view I changed. Hope this may help others

requestLayout()方法将测量和布局视图。因此,效率非常低。我现在使用的invalid()方法只会重绘我更改的视图。希望这可以帮助别人

更多相关文章

  1. 无法将视图添加到相对布局
  2. ListView的上拉弹簧、下拉弹簧,下拉弹簧时动态带刷新和切换换刷新
  3. 在android上滚动时,列表视图的位置会发生变化
  4. Java如果提高反射效率
  5. 如何在android中的recycler视图中显示第一项的选择?
  6. springMVC使用html视图配置详解
  7. C/C++比java效率高的原因?
  8. java 和 C 代码运行效率的比较(整理)
  9. 自定义视图无法工作,直到我触摸屏幕

随机推荐

  1. HTML5--1,html5的生前身后
  2. 大神,你们都在吗???来救救我吧
  3. 如何将每个单词都包含在一个span中,同时保
  4. 长征火箭残骸坠落湖南 砸坏民宅和高压线
  5. 为什么从HTML的select控件中获得的值为空
  6. android 中的线性布局与相对布局
  7. 如何将这些Twitter bootstrap 3导航栏链
  8. Ubuntu的FireFox无法使用HTML5播放器的解
  9. 使用HTML5 canvas做地图(3)图片加载平移放
  10. html——ul、li导航栏居中的两种办法