阅读量:111
要实现Android TextView滚动到特定位置,您可以使用以下方法:
- 使用ScrollView:将TextView放在ScrollView中,并使用
smoothScrollTo()方法来滚动到特定位置。例如:
ScrollView scrollView = findViewById(R.id.scrollView);
TextView textView = findViewById(R.id.textView);
int scrollToY = 100; // 滚动到的位置
scrollView.smoothScrollTo(0, scrollToY);
- 使用TextView的
scrollTo()方法:直接使用TextView的scrollTo()方法来滚动到特定位置。例如:
TextView textView = findViewById(R.id.textView);
int scrollToY = 100; // 滚动到的位置
textView.scrollTo(0, scrollToY);
- 使用NestedScrollView:如果您的TextView嵌套在NestedScrollView中,您也可以使用
smoothScrollTo()方法来实现滚动到特定位置。例如:
NestedScrollView nestedScrollView = findViewById(R.id.nestedScrollView);
TextView textView = findViewById(R.id.textView);
int scrollToY = 100; // 滚动到的位置
nestedScrollView.smoothScrollTo(0, scrollToY);
通过以上方法,您可以实现Android TextView滚动到特定位置的功能。