赞
踩
项目开发中遇到了这样的一个问题,界面最外层是ScrollView,然后里面有嵌套了一个ListView还有其他可以获取焦点的View,然后每次打开界面都会自动滚动到最底部,经过一番折腾,发现了一个简单的方法,
方法一:
获取ScrollView里面一个上层任意view,然后调用如下方法:
view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.requestFocus();
方法二:
或者将scrollview包裹的内容设置上以下两个属性
android:focusable="true"
android:focusableInTouchMode="true"
- <ScrollView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:scrollbars="none"
- >
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:focusable="true"
- android:focusableInTouchMode="true" />
- </ScrollView>
完!!!
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。