zoukankan      html  css  js  c++  java
  • 自定义插值器简单实现

    package com.loaderman.customviewdemo;
    
    import android.animation.ValueAnimator;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.TextView;
    
    public class MainActivity extends AppCompatActivity {
        TextView tv;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            tv = (TextView)findViewById(R.id.tv);
    
            findViewById(R.id.start_anim).setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    ValueAnimator animator = ValueAnimator.ofInt(0,300);
    
                    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        public void onAnimationUpdate(ValueAnimator animation) {
                            int curValue = (Integer)animation.getAnimatedValue();
                            tv.layout(tv.getLeft(),curValue,tv.getRight(),curValue+tv.getHeight());
                        }
                    });
                    animator.setDuration(1000);
                    animator.setInterpolator(new MyInterpolator());//使用自定义插值器
                    animator.start();
                }
            });
        }
    
    
    }
    package com.loaderman.customviewdemo;
    
    import android.animation.TimeInterpolator;
    
    public class MyInterpolator implements TimeInterpolator {
        public float getInterpolation(float input) {
            return 1-input;
        }
    }
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="center"
        tools:context="com.loaderman.customviewdemo.MainActivity">
    
        <Button
            android:id="@+id/start_anim"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="开始动画"/>
        <TextView
            android:id="@+id/tv"
            android:layout_toRightOf="@id/start_anim"
            android:layout_marginLeft="30dp"
            android:layout_width="50dp"
            android:layout_height="20dp"
            android:background="#ffff00"/>
    </LinearLayout>

    效果:

  • 相关阅读:
    修改hive内存限制
    hbase的regionserver宕机
    hbase的regionserver宕机
    根据硬件配置后mapred-site.xml和yarn-site.xml
    根据硬件配置后mapred-site.xml和yarn-site.xml
    阿里RDS备份恢复
    Spring框架(一)
    JVM垃圾回收机制(二)
    JVM垃圾回收机制(一)
    SpringBoot中的入口类SpringApplication
  • 原文地址:https://www.cnblogs.com/loaderman/p/10195551.html
Copyright © 2011-2022 走看看