一说到动态递增设置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的值。显示很流畅。不信能够自己试试!

android 动态设置TextView值,例:金额添加的更多相关文章

  1. android 动态设置TextView值,例:金额增加

    一说到动态递增设置TextView值,很多人应该马上就想到起个线程,让后在线程中睡眠指定时间,使用handler发送消息更新TextView值! 这样是实现了动态递增设置TextView值但是效率不咋 ...

  2. Android 动态设置TextView的drawableLeft等属性

    首先,我们在开发过程中,会经常使用到android:drawableLeft="@drawable/ic_launcher"这些类似的属性: 关于这些属性的意思,无非是在你的tex ...

  3. Android中设置TextView的颜色setTextColor

    tv.setTextColor(Color.parseColor("#FFFFFF")); tv.setTextColor(Color.WHITE); tv.setTextColo ...

  4. 【转】Android中设置TextView的颜色setTextColor--代码中设置字体颜色

    原文网址:http://www.cnblogs.com/myphoebe/archive/2012/01/06/2314728.html android中设置TextView的颜色有方法setText ...

  5. 【转】Android中设置TextView的颜色setTextColor

    原文网址:http://www.cnblogs.com/myphoebe/archive/2012/01/06/2314728.html android中设置TextView的颜色有方法setText ...

  6. [转]Android中设置TextView的颜色setTextColor

    [转自]http://txlong-onz.iteye.com/blog/1249609 Android中设置TextView的颜色setTextColor android中设置TextView的颜色 ...

  7. Android 动态设置控件获取焦点

    之前写过一篇博客,简单的介绍了Android 隐藏EditText的焦点,之所以要隐藏EditText的焦点,是因为当应用在第一次进入某个Activity时,由于该页面中的EditText获取了焦点, ...

  8. Android如何设置TextView的行间距、行高。

         Android系统中TextView默认行间距比较窄,不美观.     我们可以设置每行的行间距,可以通过属性android:lineSpacingExtra或android:lineSpa ...

  9. Ext.form.Label组件动态设置html值

    解决方法: (1)用的是 Ext.getCmp(id).setText('XXXX')可以动态设置label 显示的文本值,但是文本中有个别数字需要改变颜色显示,需要加样式,这种方法会把加样式的标签( ...

随机推荐

  1. PowerDesigner怎么调出工具箱?

    PowerDesigner怎么调出工具箱? 如图操作:

  2. windows server 2012安装.NET3.5安装提示需要指定源路径 安装.net3.5提示安装不成功,提示需要指定源路径。

    安装.net3.5提示安装不成功,提示需要指定源路径.   正确的操作步骤: 1.需要下载windows server 2012操作系统盘.用解压工具解压出来.       2012操作系统下载地址: ...

  3. 紫书 例题 10-13 UVa 830(递推)

    首先我们按照这三个U的位置来分类,当前三个U在i,i+1, i+2. 那么先看三个U前面,前面不能有三个U,因为我们不能重复计算 那么就是所有的组合减去有U的情况 为了叙述方便,我们设答案为f(n), ...

  4. 紫书 习题 10-7 UVa 10539(long long + 素数筛)

    注意要开long long 如果int * int会炸 那么久改成long long * int #include<cstdio> #include<vector> #incl ...

  5. 洛谷—— P1036 选数 || Vijos——选数

    https://vijos.org/p/1128|| https://www.luogu.org/problem/show?pid=1036#sub 描述 已知 n 个整数 x1,x2,…,xn,以及 ...

  6. Codeforces 558C Amr and Chemistry 全都变相等

     题意:给定一个数列,每次操作仅仅能将某个数乘以2或者除以2(向下取整). 求最小的操作次数使得全部的数都变为同样值. 比赛的时候最后没实现.唉.之后才A掉.開始一直在想二分次数,可是半天想不出怎 ...

  7. CF Mike and Feet (求连续区间内长度为i的最小值)单调栈

    Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. .Net商品管理(注释,百度,提问,对比,总结)

    管理控制器 using System; using System.Collections.Generic; using System.Linq; using System.Web; using Sys ...

  9. Android控件-TabHost(一)

    什么是TabHost? TabHost组件的主要功能是可以进行应用程序分类管理,例如:在用户使用windows操作系统的时候,经常见到如图所示的图形界面.     TabHost选项卡,说到这个组件, ...

  10. 浅谈 C 语言中模块化设计的范式

    今天继续谈模块化的问题.这个想慢慢写成个系列,但是不一定连续写.基本是想起来了,就整理点思路出来.主要还是为以后集中整理做点铺垫. 我们都知道,层次分明的代码最容易维护.你可以轻易的换掉某个层次上的某 ...