我想在動畫播放時鎖定ontouch監聽器。這是我的代碼。鎖ontouch監聽器
public class MainActivity extends Activity implements OnTouchListener {
boolean gifIsPlaying;
long PLAYING_TIME_OF_GIF = 111;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GIFWebView view = new GIFWebView
(this, "file:///android_asset/imageedit_ball.gif");
gifIsPlaying = true;
new Handler().postDelayed(new Runnable() {
public void run() {
gifIsPlaying = false;
}
}, PLAYING_TIME_OF_GIF);
setContentView(view);
view.setOnTouchListener(this);
}
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (gifIsPlaying) {
// No response to touch events
} else {
// Respond to touch events
GIFWebView view1 = new GIFWebView
(this, "file:///android_asset/imageedit_ball.gif");
gifIsPlaying = true;
new Handler().postDelayed(new Runnable() {
public void run() {
gifIsPlaying = false;
}
}, PLAYING_TIME_OF_GIF);
setContentView(view1);
}
// Consume touch event
return true;
}
}
我試過在ontouch中實現ontouch但沒用。我想temperory鎖ontouch,直到gif動畫完成一個循環。請幫忙。
在onTouch中使用布爾變量來執行代碼...您可以使用TimerTask等待一段時間並切換布爾變量。 – bakriOnFire
public boolean isAnimationOn = false; public boolean onTouch(View v,MotionEvent event){if(isAnimationOn) return false; else return true; }我嘗試使用這個,但沒有工作 – Meghs
提供,美曾使用正確的代碼實現.. – bakriOnFire