首页 > 其他 > 详细

(四十六)一个属性动画的经典例子

时间:2015-02-26 18:16:23      阅读:209      评论:0      收藏: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();
    }
}

 

(四十六)一个属性动画的经典例子

原文:http://www.cnblogs.com/fuyanan/p/4301735.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!