如何在translate.animate
正在進行時使按鈕不可點擊。我試着用button.setclickable(false)
和button.setEnabled(false)
這兩個辛苦工作給我。如何在Android上進行動畫製作時設置按鈕不可點擊?
這裏是我的代碼:
b2.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
if(i%2==0)
{
//b2.setClickable(false);
// Toast toast1 = Toast.makeText(getBaseContext(), "Success", 1);
// toast1.show();
if(i==0)
{
//b2.setOnClickListener(null);
b2.setEnabled(false);
//b2.setClickable(false);
int modifierY;
modifierY=-70;
Animation translateAnimation=new TranslateAnimation(0, 0, 0, modifierY);
translateAnimation.setDuration(600);
translateAnimation.setFillEnabled(true);
MyAnimationListener listener=new MyAnimationListener(b2, modifierY,SimpleViewPagerforAndroidActivity.this);
translateAnimation.setAnimationListener(listener);
// b2.setOnClickListener(null);
Animation translateAnimation1=new TranslateAnimation(0, 0, 0,0);
translateAnimation1.setDuration(1000);
translateAnimation1.setFillEnabled(true);
MyAnimationListener listener1=new MyAnimationListener(main, 0,SimpleViewPagerforAndroidActivity.this);
translateAnimation1.setAnimationListener(listener1);
main.setVisibility(RelativeLayout.VISIBLE);
/* long time =AnimationUtils.currentAnimationTimeMillis();
main.invalidate();
b2.invalidate();
translateAnimation.setStartTime(time);
translateAnimation1.setStartTime(time);*/
main.startAnimation(translateAnimation1);
b2.startAnimation(translateAnimation);
i++;
// b2.setOnClickListener(this);
}
else
{
//b2.setOnClickListener(null);
b2.setEnabled(false);
//b2.setClickable(false);
int modifierY;
modifierY=-70;
Animation translateAnimation=new TranslateAnimation(0, 0, 0, modifierY);
translateAnimation.setDuration(1000);
translateAnimation.setFillEnabled(true);
MyAnimationListener listener=new MyAnimationListener(b2, modifierY,SimpleViewPagerforAndroidActivity.this);
translateAnimation.setAnimationListener(listener);
Animation translateAnimation1=new TranslateAnimation(0, 0, 0,-150);
translateAnimation1.setDuration(600);
translateAnimation1.setFillEnabled(true);
MyAnimationListener listener1=new MyAnimationListener(main, -150,SimpleViewPagerforAndroidActivity.this);
translateAnimation1.setAnimationListener(listener1);
main.setVisibility(RelativeLayout.VISIBLE);
/* long time =AnimationUtils.currentAnimationTimeMillis();
main.invalidate();
b2.invalidate();
translateAnimation.setStartTime(time);
translateAnimation1.setStartTime(time);*/
main.startAnimation(translateAnimation1);
b2.startAnimation(translateAnimation);
// b2.setOnClickListener(this);
i++;
}
}
else
{
//b2.setOnClickListener(null);
b2.setEnabled(false);
//b2.setClickable(false);
Animation translateAnimation=new TranslateAnimation(0, 0, 0,150);
translateAnimation.setDuration(1000);
translateAnimation.setFillEnabled(true);
MyAnimationListener listener=new MyAnimationListener(main, 150,SimpleViewPagerforAndroidActivity.this);
translateAnimation.setAnimationListener(listener);
Animation translateAnimation1=new TranslateAnimation(0, 0, 0,70);
translateAnimation1.setDuration(600);
translateAnimation1.setFillEnabled(true);
MyAnimationListener listener1=new MyAnimationListener(b2, 70,SimpleViewPagerforAndroidActivity.this);
translateAnimation1.setAnimationListener(listener1);
/* long time =AnimationUtils.currentAnimationTimeMillis();
main.invalidate();
b2.invalidate();
translateAnimation.setStartTime(time);
translateAnimation1.setStartTime(time);
main.startAnimation(translateAnimation1);
b2.startAnimation(translateAnimation);*/
b2.startAnimation(translateAnimation1);
main.startAnimation(translateAnimation);
i++;
//b2.setOnClickListener(this);
}
}
});
請發佈代碼段 – Rajesh
使用AsyncTask這是當你需要做一些背景,而另一個任務正在運行,.... – SilentKiller
你已經嘗試在動畫回調函數中設置它。 –