2012-01-22 6 views
0

Horizo​​ntalScrollViewで2つのボタン(左に1つ、右に1つ)を使用してスクロールしようとしています。 私は連続したスクロールを手に入れることはできません。 誰かを助けることができますか?ボタンでスクロールする

どちらの例ではなく、連続ではない、仕事:

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; 
} 

答えて

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; 
    } 
+0

は良いが、私はチェックして、私はあなたがsayd何​​しようとした – Oliver

+0

ことなかったです、アプリがクラッシュします。理由は分かりません。 –

+0

を教えて、答えを編集した – Oliver

関連する問題