2015-06-01 55 views
0

我在onDispatchKeyEvent中以编程方式滚动TextView。当我滚动很多时,我可以将文本移到边界或边界下方,以便只显示一半。Android:防止TextView通过边界以编程方式滚动

@Override 
public boolean dispatchKeyEvent(KeyEvent event) { 
if (event.getKeyCode() == KeyEvent.KEYCODE_MOVE_HOME && event.getAction() == KeyEvent.ACTION_DOWN) { 

outputTextView.scrollBy(0, +50); 

} 
} 

我该如何预防?

回答

0

你可以试着记住您当前的位置,并检查是否可以sroll更多

curr_pos += 50 
if(curr_pos < outputTextView.getBottom()){ 
    outputTextView.scrollBy(0, +50); 
}else{ 
    curr_pos -=50 
} 

或尝试重写.onScrollChanged(int, int, int, int)这是由.scrollBy(int, int)调用。

相关问题