我想在播放动画时锁定 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 但没有用。我想临时锁定 ontouch 直到 gif 动画完成一个循环。请帮忙。