zoukankan      html  css  js  c++  java
  • android 动态设置TextView值,例:金额添加

    一说到动态递增设置TextView值,非常多人应该立即就想到起个线程,让后在线程中睡眠指定时间,使用handler发送消息更新TextView值!

    这样是实现了动态递增设置TextView值可是效率不咋滴吧,须要的话能够自己去试试,如1到100,10s内显示完,会感觉到有点卡的。


    这里有个更好的方法,使用ValueAnimator进行设置,并且不须要自己去计算每次叠加后须要间隔的时间,以下是代码:


    public static void autoIncrement(final TextView target, final float start,
    			final float end, long duration) {
    
    		ValueAnimator animator = ValueAnimator.ofFloat(start, end);
    
    		animator.addUpdateListener(new AnimatorUpdateListener() {
    			private FloatEvaluator evalutor = new FloatEvaluator();
    			private DecimalFormat format = new DecimalFormat("####0.0#");
    
    			@Override
    			public void onAnimationUpdate(ValueAnimator animation) {
    
    				float fraction = animation.getAnimatedFraction();
    				float currentValue = evalutor.evaluate(fraction, start, end);
    				target.setText(format.format(currentValue));
    			}
    		});
    		animator.setDuration(duration);
    		animator.start();
    
    	}


    在2s内显示1-1000的值。显示很流畅。不信能够自己试试!





  • 相关阅读:
    python模块win32com中的early-bind与lazy-bind(以Autocad为例)
    Beautiful code and beautiful life
    PyPI 使用的国内源
    JavaScript在SublimeText中的配置
    Python中的模块包
    FTP 服务器在WIN10上的搭建及服务端下载文件实例
    Oracle ASM磁盘组兼容性
    oracle ADVM
    053-28
    053-27
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/5160338.html
Copyright © 2011-2022 走看看