1
我想滚动textview
而button
处于按下状态。只要用户释放button
,我想停止滚动。我在按钮上使用setOnTouchListener
。但我无法做到这一点。任何人都可以请帮助我,并分享一些代码来做到这一点。Android TextVIew在按钮保持按下状态时滚动
arrow_up.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
lastDown = System.currentTimeMillis();
System.out.println(System.currentTimeMillis());
flag = true;
method();
} else if (event.getAction() == MotionEvent.ACTION_UP) {
System.out.println(System.currentTimeMillis() - lastDown);
flag = false;
method();
}
return false;
}
});
public void method() {
while(flag == true){
try {
Thread.sleep(500);
System.out.println("Flag === " + flag);
tv.scrollBy(0, -20);
} catch (Exception e) {
e.printStackTrace();
}
}
}
谢谢。尝试你的代码。 –