java - ScrollView 总是滚动到底部

标签 java android scrollview

我在我的布局中定义了一个带有 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 的底部。不幸的是,这不能正常工作。它向下滚动,但并不总是向下滚动,也不总是向下滚动。有什么提示吗?

最佳答案

或在 scrollView 中更改 View 大小后使用:

scroller.post(new Runnable() { 
    public void run() { 
        scroller.fullScroll(ScrollView.FOCUS_DOWN); 
    } 
}); 

关于java - ScrollView 总是滚动到底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2832701/

相关文章:

listview - Flutter:ListView不可滚动,不可弹跳

android - ScrollView 和 LinearLayout 的困难

java - 为什么在构建此项目时会出现 "No assembly descriptors found."错误?

Jpanel添加Jpanel后Java Swing repaint()、revalidate()问题

android - 如何将通过 UrlImageViewHelper 下载的图像保存到 Android 上的 SD 卡?

android - 将 LinearView 和 ExpandableListView 放入 ScrollView 是否可能且有效

java - Json比较异常: Can't access getJSONArray in java

java - 有没有难以反编译的代码示例?

android - 以编程方式创建 View 时,如何知道要使用哪个 LayoutParams 类?

android - 如何避免在 onDraw 时创建 Rect 对象