[英]How to make textView scroll vertically automatically?
I want my textView to start automatically scrolling (vertically) when my activity starts I am displaying a paragraph in a small textView. 我希望我的活动开始时,我的textView开始自动(垂直)滚动,所以我会在一个小的textView中显示一个段落。 The textView is manually scrollable vertically but I want it to do this on its own.
textView可以手动手动垂直滚动,但我希望它自己执行此操作。
I added this attribute but it did not help. 我添加了此属性,但没有帮助。
android:gravity = "bottom"
Thanks 谢谢
<TextView
android:id="@+id/announcementNewsText"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:autoSizeTextType="uniform"
android:scrollbars="vertical"
android:textColor="#FFFFFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline"
app:layout_constraintVertical_bias="1.0"
/>
Add scroll view in your XML like this 像这样在您的XML中添加滚动视图
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scroll_view">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/announcementNewsText"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:autoSizeTextType="uniform"
android:scrollbars="vertical"
android:textColor="#FFFFFF"/>
</RelativeLayout>
</ScrollView>
And in java onCreate() find the scroll view 然后在java onCreate()中找到滚动视图
ScrollView s = findViewById(R.id.scroll_view);
s.setSmoothScrollingEnabled(true);
s.post(new Runnable() {
@Override
public void run() {
s.fullScroll(View.FOCUS_DOWN);
}
});
Add 加
android:scrollbars = "vertical"
to your textView
and use 到您的
textView
并使用
yourTextView.setMovementMethod(new ScrollingMovementMethod());
in your code. 在您的代码中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.