1mResultTextView.setText(strResultText); 2//通过行数X行高计算文字段落高度 3int offset = mResultTextView.getLineCount() *mResultTextView.getLineHeight(); 4//如果文字段落高度大于可显示高度,则滑动到末尾(+20是为了让末尾不贴边) 5if(offset -mResultTextView.getHeight() >0) 6 mResultTextView.scrollTo(0, offset -mResultTextView.getHeight() +20);
相应的XML文件属性:
1<TextView android:id="@+id/result_text" 2 android:layout_width="match_parent" 3 android:layout_height="match_parent" 4 android:padding="5dp" 5 android:scrollbars="vertical" 6 android:fadeScrollbars="false"> 7</TextView>