Android Button Animation. How To Get Animation First, On Click Before Activity
I made a button for Android that rotates on click, but when I set a button and new activity, when I click it's just set me to new activity. I need just this: when I click on that b
Solution 1:
You can set animation listener
, when finish animation
start your activity
.
Please refer this link
Example code (must update based on your purpose):
ImageButton pandaButton2 = (ImageButton) findViewById(R.id.pandaButton2);
pandaButton2.setOnClickListener(newOnClickListener(){
publicvoidonClick(View v){
v.startAnimation(pandarotate);
}
});
pandarotate.setAnimationListener(newAnimation.AnimationListener() {
@OverridepublicvoidonAnimationStart(Animation animation) {
}
@OverridepublicvoidonAnimationEnd(Animation animation) {
startActivity(newIntent("com.example.threepandas.MENU"));
}
@OverridepublicvoidonAnimationRepeat(Animation animation) {
}
});
Solution 2:
insert a delay for the length of the animation after the animation starts and before the activity starts
try {
Thread.sleep(1000); //1000 milliseconds is one second.
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
Solution 3:
Here is the solution I use for this problem (got it from the Google I/O App Source Code on Github)
privatestaticfinalintDELAY=250;
private Handler mHandler;
@OverridepublicvoidonClick(final View view) {
switch (view.getId()) {
case R.id.button:
mHandler.postDelayed(newRunnable() {
@Overridepublicvoidrun() {
}
}, DELAY);
break;
}
}
Post a Comment for "Android Button Animation. How To Get Animation First, On Click Before Activity"