当前位置:   article > 正文

Android控件ScrollView默认滚动到底部的解决方法_安卓进入 activity时scrollvieww无法自动滚动到底部

安卓进入 activity时scrollvieww无法自动滚动到底部

项目开发中遇到了这样的一个问题,界面最外层是ScrollView,然后里面有嵌套了一个ListView还有其他可以获取焦点的View,然后每次打开界面都会自动滚动到最底部,经过一番折腾,发现了一个简单的方法,

方法一:

获取ScrollView里面一个上层任意view,然后调用如下方法:

view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.requestFocus();

方法二:

或者将scrollview包裹的内容设置上以下两个属性

  android:focusable="true"  

  android:focusableInTouchMode="true"

  1. <ScrollView
  2. android:layout_width="match_parent"
  3. android:layout_height="wrap_content"
  4. android:scrollbars="none"
  5. >
  6. <LinearLayout
  7. android:layout_width="wrap_content"
  8. android:layout_height="match_parent"
  9. android:orientation="vertical"
  10. android:focusable="true"
  11. android:focusableInTouchMode="true" />
  12. </ScrollView>

完!!!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/312626
推荐阅读
相关标签
  

闽ICP备14008679号