【发布时间】:2013-08-17 09:46:25
【问题描述】:
我想在动画播放时锁定 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 动画完成一个循环。请帮忙。
【问题讨论】:
-
在onTouch里面使用一个布尔变量来执行代码……你可以使用一个TimerTask等待一段时间,然后切换布尔变量。
-
公共布尔 isAnimationOn = false; public boolean onTouch(View v, MotionEvent event){ if (isAnimationOn) return false;否则返回真;我试过用这个但不工作
-
提供你使用过的正确代码实现..
-
@Override public boolean onTouch(View v, MotionEvent event) { // TODO 自动生成的方法存根 if (event.getAction() == MotionEvent.ACTION_DOWN) { if (loaded) { return false ; } else { GIFWebView view1 = new GIFWebView (this, "file:///android_asset/imageedit_ball.gif");设置内容视图(视图 1); view1.setOnTouchListener(this); } } 返回真; }
标签: android touch-event