如何使scrollBy直接工作?

时间:2014-05-22 03:19:50

标签: android scrollview

Scroll By不会直接触发。怎么做?请帮忙。我是这方面的新手。 : - (

//declaration of my ScrollView

scroll = (ScrollView) findViewById(R.id.scrollMe);

private View.OnFocusChangeListener focusListenertest = new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        // TODO Auto-generated method stub
         if(myTextBox.hasFocus())
         {
             scroll.post(new Runnable() {
                    @Override
                    public void run() {
                        scroll.scrollBy(0 , +30);
                    }
                });
         }

    }
}; 

1 个答案:

答案 0 :(得分:0)

而不是myTextBox.hasFocus()使用v.hasFocus而且我不认为runnable需要直接调用scroll.scrollBy(0 , +30);

所以你的代码就像这样

  scroll = (ScrollView) findViewById(R.id.scrollMe);

private View.OnFocusChangeListener focusListenertest = new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
    // TODO Auto-generated method stub
     if(v.hasFocus())
     {

                    scroll.scrollBy(0 , +30);//if u get exception or ANR then use Runnable the way u did

     }

}
};