用按钮滚动

时间:2012-01-22 21:06:22

标签: android scroll

我正在尝试使用2个按钮在Horizo​​ntalScrollView中滚动,一个用于左侧,一个用于右侧。 我只能在触摸时才能获得连续的卷轴。 有人可以帮忙吗?

这两种情况都有效,但不是连续的:

public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.bRight:
if(event.getAction() == MotionEvent.ACTION_DOWN){
sw.smoothScrollBy(20, 0);
}
break;
case R.id.bLeft:
sw.smoothScrollBy(-20, 0);
break;
}
return false;
}

1 个答案:

答案 0 :(得分:0)

试试这个:

    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub
        switch(v.getId()){
        case R.id.bRight:
            while(event.getAction() == MotionEvent.ACTION_DOWN){
                sw.smoothScrollBy(20, 0);
                for(int i=0;i<10000;i++); //this only adds delay between scrolls, adjust as needed or remove
            }
            return true;
        case R.id.bLeft:
            while(event.getAction() == MotionEvent.ACTION_DOWN){
                sw.smoothScrollBy(-20, 0);
                for(int i=0;i<10000;i++); //this only adds delay between scrolls, adjust as needed or remove
            }
            return true;
        }
        return false;
    }