安卓過渡動畫 ViewAnimationUtils簡單介紹使用
阿新 • • 發佈:2018-11-30
安卓5.0的過渡動畫學習記錄一下。效果如圖
()
1.方法原始碼
public static Animator createCircularReveal(View view,
int centerX, int centerY, float startRadius, float endRadius) {
return new RevealAnimator(view, centerX, centerY, startRadius, endRadius);
}
引數說明:
view:代表的是你要操作的view centerX:圓的x方向的中點 centerY:圓的y方向的中點 startRadius:這個圓開始時候的半徑 endRadius:結束時候的半徑
2.示例程式碼
package com.example.a37443.viewanimationutil; import android.animation.Animator; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.ViewAnimationUtils; import android.widget.Button; import android.widget.ImageView; import android.widget.Switch; import android.widget.Toast; public class MainActivity extends AppCompatActivity { ImageView img; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); img = (ImageView)findViewById(R.id.img); } public void Onclick(View v){ switch(v.getId()){ case R.id.btn_1: //對角過渡 Animator animator = ViewAnimationUtils.createCircularReveal(img,0,0,0, (float) Math.hypot(img.getWidth(), img.getHeight())); animator.setDuration(2000); animator.start(); break; case R.id.btn_2: //中心 Animator animator2 = ViewAnimationUtils.createCircularReveal(img,img.getWidth()/2,0,0, (float) Math.hypot(img.getWidth(), img.getHeight())); animator2.setDuration(1500); animator2.start(); break; case R.id.btn_3: //從內到外 Animator animator3 = ViewAnimationUtils.createCircularReveal(img,img.getWidth()/2,img.getHeight()/2,0, img.getWidth()); animator3.setDuration(2000); animator3.start(); break; case R.id.btn_4: //從外到內 Animator animator4 = ViewAnimationUtils.createCircularReveal(img,img.getWidth()/2,img.getHeight()/2,img.getWidth(), 0); animator4.setDuration(2000); animator4.start(); break; default: break; } } }
還有其他特效就等待發掘了,學習mark~