(四十六)一个属性动画的经典例子(让TextView中的数值从某一个值变成0再变到另一个值)
2015-02-26 17:19
567 查看
1、demo的结构图
2、CustomFontPercedntTextView.java的代码
2、MainAcitivity.java的代码
2、CustomFontPercedntTextView.java的代码
package com.example.propertyanimation; import android.content.Context; import android.util.AttributeSet; import android.widget.TextView; public class CustomFontPercedntTextView extends TextView { private int percentage; public CustomFontPercedntTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public CustomFontPercedntTextView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomFontPercedntTextView(Context context) { super(context); } public int getPercentage() { return percentage; } public void setPercentage(int percentage) { this.percentage = percentage; setText(percentage + "%"); } }
2、MainAcitivity.java的代码
package com.example.propertyanimation; import android.animation.AnimatorInflater; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.animation.LinearInterpolator; import android.widget.TextView; public class MainActivity extends Activity { private CustomFontPercedntTextView tv_percentage; private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView) findViewById(R.id.tv); } public void click(View view) { tv_percentage = (CustomFontPercedntTextView) this .findViewById(R.id.cftv); PropertyValuesHolder prvh = PropertyValuesHolder.ofInt("percentage", 30, 0, 70); ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder( this.tv_percentage, prvh); anim.setDuration(5000); anim.setInterpolator(new LinearInterpolator()); anim.start(); AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.property_animator); set.setTarget(tv); set.start(); } }
相关文章推荐
- Android 属性动画监听事件与一个菜单的例子
- Android 属性动画监听事件与一个菜单的例子
- 在一个Activity里面的TextView上面添加网页链接,启动后到另一个Activity里面!
- Android 一个视图界面内某一View设置动画,其他视图view.setvisibility无效得解决方法
- TextView使用小技巧——一个TextView多重属性设置(SpannableStringBuilder)
- Android 点击ListView(或GridView)的一个item,使其里面textview变色,点击另一个这个恢复原来颜色
- 一个功能强大的 TextView,可以满足日常大部分布局方式,开发者可已自行组合属性配置出属于自己风格的样式!
- ios-day06-03(UITableView的索引条、一个对象作为另一个对象的属性、valueForKey和valueForKeyPath的区别)
- 如图实现一个textview在另一个textview的右上角
- 一个得到添加属性(下拉条)brandss,某一特定值下的所有产品的例子
- 一个imageview播放动画,如此简单(包含imageview的所有属性,方法)
- Android属性动画实现TextView类似支付宝余额数字滚动
- 一个有上下滚动动画的TextView
- 如何打印一个类的属性(例如textview里的控件等,基于oc里没有绝对的私有变量这一规则实现)
- 一个自定义的android TextView控件例子
- 在一个Activity里面的TextView上面添加网页链接,启动后到另一个Activity里面!
- 在一个Activity里面的TextView上面添加网页链接,启动后到另一个Activity里面!
- PHP跳转到另一个画面,并且带着该行内的一个数值作为参数传递给下一个页面.能给例子吗
- ios 动画 创建一个UIImageView并将其属性设置animationImages为UIImages 的数组
- 收藏两个位图切割实现动画效果的例子(一个是用位图切割的方式,另一个是用scrollRect)