在textview中添加一个大字符串后,如何滚动回字符串的初始部分? 我正在使用以下textview
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="50sp"
android:singleLine="true"
android:gravity="end"
android:layout_gravity="end"
android:layout_marginTop="40dp">
如何让它从右向左滚动?
答案 0 :(得分:1)
试试这段代码。
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/scroll" >
<TextView
android:id="@+id/textViewId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollHorizontally="true"
android:text="your_big_string"/>
</HorizontalScrollView>
在您的activity.java中,添加此
final HorizontalScrollView scrollView = (HorizontalScrollView) findViewById(R.id.scroll);
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
}, 100L);