效果:
java: 用handler循环调用这个方法即可,而且传入的两个参数分别是ScrollView,LinearLayout
- public static void scroll2Bottom(final ScrollView scroll, final View inner) {
- Handler handler = new Handler();
- handler.post(new Runnable() {
- @Override
- public void run() {
- // TODO Auto-generated method stub
- if (scroll == null || inner == null) {
- return;
- }
- // 内层高度超过外层
- int offset = inner.getMeasuredHeight()
- - scroll.getMeasuredHeight();
- if (offset < 0) {
- System.out.println("定位...");
- offset = 0;
- }
- scroll.scrollTo(0, offset);
- }
- });
- }
XML: 关键设置scrollview的:android:fadeScrollbars="false"表示始终显示垂直滚动条
- <ScrollView
- android:id="@+id/sv_show"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_above="@id/tl_botton"
- android:layout_alignParentTop="true"
- android:background="#E6E6FA"
- android:fadeScrollbars="false"
- android:scrollbarAlwaysDrawVerticalTrack="true"
- android:scrollbars="vertical" >
- <LinearLayout
- android:id="@+id/ll_layout"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:background="#00FF00" >
- <TextView
- android:id="@+id/tv_show"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="#FFC0CB"
- android:padding="@dimen/padding_medium"
- android:scrollbars="vertical"
- android:text="@string/hello_world"
- tools:context=".MainActivity" />
- </LinearLayout>
- </ScrollView>
- 而且需要注意的是:调用方法是传入的两个参数分别是ScrollView,LinearLayout的实例!