zoukankan      html  css  js  c++  java
  • (四十六)一个属性动画的经典例子(让TextView中的数值从某一个值变成0再变到另一个值)

    1、demo的结构图

    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();
        }
    }
  • 相关阅读:
    02-线性结构2 一元多项式的乘法与加法运算
    两个堆栈实现列队
    队列的顺序存储和链式存储实现
    包含MIN函数的栈+一个数组实现两个堆栈+两个数组实现MIN栈
    利用纯java捕获和播放音频
    许令波老师的java的IO机制分析文章
    soundtouch源码分析__based on csdn :
    java桌面项目打包_by icewee_写得太棒了,直接转载了
    白化检验( 白噪声准则检验 )
    对于冯嘉礼老师定性映射理论的复习
  • 原文地址:https://www.cnblogs.com/fuyanan/p/4301735.html
Copyright © 2011-2022 走看看