[英]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. 我为Android制作了一个按钮,该按钮可以在点击时旋转,但是当我设置按钮和新活动时,单击它只是将我设置为新活动。
I need just this: when I click on that button, first to do animation eg rotate, then to execute a new activity. 我只需要这样:当我单击该按钮时,首先要进行动画处理,例如旋转,然后执行新的活动。 Here is my code:
这是我的代码:
ImageButton pandaButton2 = (ImageButton) findViewById(R.id.pandaButton2);
pandaButton2.setOnClickListener(new OnClickListener(){
public void onClick(View v){
v.startAnimation(pandarotate);
startActivity(new Intent("com.example.threepandas.MENU"));
}
});
You can set animation listener
, when finish animation
start your activity
. 您可以设置
animation listener
, animation
完成后开始您的activity
。 Please refer this link 请参考此链接
Example code (must update based on your purpose): 示例代码(必须根据您的目的进行更新):
ImageButton pandaButton2 = (ImageButton) findViewById(R.id.pandaButton2);
pandaButton2.setOnClickListener(new OnClickListener(){
public void onClick(View v){
v.startAnimation(pandarotate);
}
});
pandarotate.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
startActivity(new Intent("com.example.threepandas.MENU"));
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
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();
}
Here is the solution I use for this problem (got it from the Google I/O App Source Code on Github) 这是我用于解决此问题的解决方案(可从Github上的Google I / O应用源代码中获得)
private static final int DELAY = 250;
private Handler mHandler;
@Override
public void onClick(final View view) {
switch (view.getId()) {
case R.id.button:
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
}
}, DELAY);
break;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.