2014-05-22 24 views
0

滾動按鈕不會直接觸發。怎麼做?請幫忙。我是這個新手。 :-(如何讓scrollBy直接運行?

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

    } 
}; 
+0

寫下您的問題或一些事你面對的任何一種錯誤 –

+0

我沒有遇到任何錯誤,我唯一擔心的是,爲什麼它的滾動方法doest不能直接觸發?請幫助我 – user3651152

+0

當你想滾動點擊任何butto n或其他東西 –

回答

0

代替myTextBox.hasFocus()使用v.hasFocus,也是我不認爲運行的直接調用需要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 

    } 

} 
}; 
+0

感謝您的評論。我會嘗試這個,稍後我會通知你。謝謝。 – user3651152

+0

我之所以使用文本框,是爲了讓每個關注文本框的滾動條都會觸發。但再次感謝,我會先嚐試。希望你能幫助我。 T – user3651152

+0

仍然沒有工作。:-(。 – user3651152