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的值。显示很流畅。不信能够自己试试!
android 动态设置TextView值,例:金额添加的更多相关文章
- android 动态设置TextView值,例:金额增加
一说到动态递增设置TextView值,很多人应该马上就想到起个线程,让后在线程中睡眠指定时间,使用handler发送消息更新TextView值! 这样是实现了动态递增设置TextView值但是效率不咋 ...
- Android 动态设置TextView的drawableLeft等属性
首先,我们在开发过程中,会经常使用到android:drawableLeft="@drawable/ic_launcher"这些类似的属性: 关于这些属性的意思,无非是在你的tex ...
- Android中设置TextView的颜色setTextColor
tv.setTextColor(Color.parseColor("#FFFFFF")); tv.setTextColor(Color.WHITE); tv.setTextColo ...
- 【转】Android中设置TextView的颜色setTextColor--代码中设置字体颜色
原文网址:http://www.cnblogs.com/myphoebe/archive/2012/01/06/2314728.html android中设置TextView的颜色有方法setText ...
- 【转】Android中设置TextView的颜色setTextColor
原文网址:http://www.cnblogs.com/myphoebe/archive/2012/01/06/2314728.html android中设置TextView的颜色有方法setText ...
- [转]Android中设置TextView的颜色setTextColor
[转自]http://txlong-onz.iteye.com/blog/1249609 Android中设置TextView的颜色setTextColor android中设置TextView的颜色 ...
- Android 动态设置控件获取焦点
之前写过一篇博客,简单的介绍了Android 隐藏EditText的焦点,之所以要隐藏EditText的焦点,是因为当应用在第一次进入某个Activity时,由于该页面中的EditText获取了焦点, ...
- Android如何设置TextView的行间距、行高。
Android系统中TextView默认行间距比较窄,不美观. 我们可以设置每行的行间距,可以通过属性android:lineSpacingExtra或android:lineSpa ...
- Ext.form.Label组件动态设置html值
解决方法: (1)用的是 Ext.getCmp(id).setText('XXXX')可以动态设置label 显示的文本值,但是文本中有个别数字需要改变颜色显示,需要加样式,这种方法会把加样式的标签( ...
随机推荐
- spark groupByKey 也是可以filter的
>>> v=sc.parallelize(["one", "two", "two", "three", ...
- centos7 配置redis
文件上传 yum -y install lrzsz 安装redis部署前操作 同时下载redis-.tar.gz安装包 yum -y install gcc-c++ yum -y install tc ...
- BZOJ 球形空间产生器 解题报告(高斯消元)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1013 1013: [JSOI2008]球形空间产生器sphere 有一个球形空间产生器能 ...
- Spring Boot AutoConfiguration注解@ConditionalXXXX之前生今世
1.注解@Conditional的定义 @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHO ...
- OpenGL编程逐步深入(七)旋转变换
准备知识 这一节我们来看一下旋转变换.旋转变换指的是给我们一个指点的点和角度,我们需要绕着过该点的轴线將对象旋转对应的角度.这里我们只改变X/Y/Z中的两个分量,第三个分量保持不变.这意味着我们的图形 ...
- Framework3.5安装(Windows8.1)
在用到Android逆向助手,使用时提示安装Framework3.5,Windows7都有Framework3.5,Windows8却没有,联网更新就算了,这龟速更新得多久.但是问题总还是要解决,随便 ...
- Method Swizzing中一般替换方法都写在Category类别里吗?有没有别的实现方式
Method Swizzing中一般替换方法都写在Category类别里吗?有没有别的实现方式 Method Swizzing中一般替换方法都写在Category类别里吗?有没有别的实现方式 > ...
- jquery on event
<!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- vue1.0父子、兄弟间 通信案例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Oracle 流程控制语句
分为选择语句循环语句两大类:一 选择语句1 if then ...end;set serveroutput on declare var_name1 varchar2(50):='East'; var ...