zoukankan      html  css  js  c++  java
  • PropertyValuesHolder学习

    package com.loaderman.customviewdemo;
    
    import android.animation.ObjectAnimator;
    import android.animation.PropertyValuesHolder;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;
    
    public class MainActivity extends AppCompatActivity {
        private Button mButton;
        private TextView mTv, mTv2;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mTv = (TextView)findViewById(R.id.tv);
            findViewById(R.id.start_anim).setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    PropertyValuesHolder rotationHolder = PropertyValuesHolder.ofFloat("Rotation", 60f, -60f, 40f, -40f, -20f, 20f, 10f, -10f, 0f);
                    PropertyValuesHolder alphaHolder = PropertyValuesHolder.ofFloat("alpha", 0.1f, 1f, 0.1f, 1f);
                    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(mTv, rotationHolder, alphaHolder);\实例入口
                    animator.setDuration(3000);
                    animator.start();
                }
            });
        }
    }

    PropertyValuesHolder的ofFloat和ofInt函数的基本用法


    package com.loaderman.customviewdemo;
    
    import android.animation.ObjectAnimator;
    import android.animation.PropertyValuesHolder;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.view.animation.AccelerateInterpolator;
    
    public class MainActivity extends AppCompatActivity {
        private MyTextView mTv;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mTv = findViewById(R.id.mTv);
            findViewById(R.id.start_anim).setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    /**
                     * ofObject使用
                     */
                    PropertyValuesHolder charHolder = PropertyValuesHolder.ofObject("CharText",new CharEvaluator(),new Character('A'),new Character('Z'));
                    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(mTv, charHolder);
                    animator.setDuration(3000);
                    animator.setInterpolator(new AccelerateInterpolator());
                    animator.start();
                }
            });
        }
    }
    package com.loaderman.customviewdemo;
    
    import android.content.Context;
    import android.util.AttributeSet;
    
    public class MyTextView extends android.support.v7.widget.AppCompatTextView {
        public MyTextView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
        public void setCharText(Character character){
            setText(String.valueOf(character));
        }
    }
    package com.loaderman.customviewdemo;
    
    import android.animation.TypeEvaluator;
    
    
    public class CharEvaluator implements TypeEvaluator<Character> {
        public Character evaluate(float fraction, Character startValue, Character endValue) {
            int startInt  = (int)startValue;
            int endInt = (int)endValue;
            int curInt = (int)(startInt + fraction *(endInt - startInt));
            char result = (char)curInt;
            return result;
        }
    }

    PropertyValuesHolder的ofobject函数的基本用法

    效果:

  • 相关阅读:
    thinkPHP 远程数据库和远程连接数据库表名大小写混合
    浏览器兼容性的问题
    input 的那些事
    jquery ui draggable失效的问题
    thinkphp在php5.6以上版本显示"No input file specified"
    ajax dataType
    DOM对象的处理
    ubuntu 16.4 中eth0添加ip地址,且可以上网
    linux 安装phpstudy
    select样式清除
  • 原文地址:https://www.cnblogs.com/loaderman/p/10206964.html
Copyright © 2011-2022 走看看