[2017-8-2]Android Learning Day8

智者不为愚者谋,勇者不为怯者死。这篇文章主要讲述[2017-8-2]Android Learning Day8相关的知识,希望能为你提供帮助。
自定义动画效果新建一个customAnim类

1 package com.liwenchi.myapplication; 2 3 import android.view.animation.Animation; 4 import android.view.animation.Transformation; 5 6 import static java.lang.Math.*; 7 8 /** 9* Created by VULCAN on 2017/8/2. 10*/ 11 12 public class CustomAnim extends Animation { 13 14@Override 15protected void applyTransformation(float interpolatedTime, Transformation t) { 16//interpolatedTime代表补间动画时间,从0~1,0代表开始,1代表结束 17//t代表变化对象 18float p = interpolatedTime; 19super.applyTransformation(interpolatedTime, t); 20//System.out.println(interpolatedTime); 21//t.setAlpha(interpolatedTime); 设置透明度 22//t.getMatrix().setTranslate(0, -300*p); 设置位置 23t.getMatrix().setTranslate((float) (sin(p*2*6.28*p)*50), 0); 24} 25 }

其中,重写applyTransformation()方法
MainActivity.java里创建一个CustomAnim动画
1 package com.liwenchi.myapplication; 2 3 import android.support.v7.app.AppCompatActivity; 4 import android.os.Bundle; 5 import android.view.View; 6 import android.view.animation.AlphaAnimation; 7 import android.view.animation.Animation; 8 import android.view.animation.AnimationSet; 9 import android.view.animation.AnimationUtils; 10 import android.view.animation.RotateAnimation; 11 import android.view.animation.ScaleAnimation; 12 import android.view.animation.TranslateAnimation; 13 import android.widget.Button; 14 import android.widget.CheckBox; 15 import android.widget.CompoundButton; 16 import android.widget.TextView; 17 18 public class MainActivity extends AppCompatActivity { 19 20private CustomAnim ca; 21 22@Override 23protected void onCreate(Bundle savedInstanceState) { 24super.onCreate(savedInstanceState); 25setContentView(R.layout.activity_main); 26slove(); 27} 28 29private void slove() { 30ca = new CustomAnim(); 31ca.setDuration(1000); 32findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() { 33 34@Override 35public void onClick(View v) { 36v.startAnimation(ca); 37} 38}); 39} 40 } 41 //v.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.ta));

【[2017-8-2]Android Learning Day8】这样就自定义了一个“摇头”的动画效果

    推荐阅读