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);
}
});
}
}
};
答案 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
}
}
};