我在布局中定义了一个带有texteedit的scrollview:
 <ScrollView android:fillViewport="true"
     android:layout_marginBottom="50dip"
     android:id="@+id/start_scroller"
     android:layout_height="fill_parent"
     android:layout_width="fill_parent"
     android:fadingEdge="none">
 <TextView  
    android:id="@+id/text"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" >
 </TextView>
 </ScrollView>
我使用以下方法向此ScrollView添加文本:
public void writeToLogView(String textMsg) {
   if (text.getText().equals("")) {
       text.append(textMsg);
   } else {
    text.append("\n" + textMsg);
    scroller.scrollBy(0, 1000000);
   }
}
如您所见,我附加文本并尝试滚动到ScrollView的底部.不幸的是,这不能正常工作.它向下滚动,但并非总是如此,并不总是向下滚动.任何提示?
Mat*_*ejC 30
或者在scrollView中更改视图大小后使用:
scroller.post(new Runnable() { 
    public void run() { 
        scroller.fullScroll(ScrollView.FOCUS_DOWN); 
    } 
}); 
在附加文本后,尝试使用TextView的尺寸来计算滚动到的位置,而不是一些常量,如下所示:
scroller.post(new Runnable() {
    public void run() {
        scroller.scrollTo(text.getMeasuredWidth(), text.getMeasuredHeight());
    }
});
| 归档时间: | 
 | 
| 查看次数: | 15472 次 | 
| 最近记录: |