解决ScrollView自动滑动到底部的问题

来源:互联网 发布:张逗张花小卖部 淘宝 编辑:程序博客网 时间:2024/05/22 02:30

ScrollView如果嵌套了ListView、GridView或者RecyclerView

当这些子控件加载完之后ScrollView就会自动滑动到底部

可以重写ScrollView中的computeScrollDeltaToGetChildRectOnScreen方法来解决这个问题


public class MyScrollView extends ScrollView {
    public MyScrollView(Context context) {
        super(context);}

    public MyScrollView(Context context,AttributeSet attrs) {
        super(context,attrs); }

    public MyScrollView(Context context,AttributeSet attrs, int defStyle) {
        super(context,attrs, defStyle);}

    @Override protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {
        return 0;}
}

阅读全文
0 0
原创粉丝点击