[英]Button animation in Android studio
在 res 文件夾中創建一個名為
alpha_animation
文件
<?xml version="1.0" encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromAlpha="1"
android:toAlpha="0.05"
android:repeatCount="5"
android:repeatMode="reverse"
/>
現在在你的活動中寫下這個
private Button mButton;
private Animation mAlphaAnimation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get the application context
mContext = getApplicationContext();
mActivity = MainActivity.this;
mButton = (Button) findViewById(R.id.btn);
mAlphaAnimation = AnimationUtils.loadAnimation(mContext,R.anim.alpha_animation);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Start the blink animation (fade in and fade out animation)
mButton.startAnimation(mAlphaAnimation);
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.