scrollview分析

scrollview的原理就是调用srcollto方法来实现内容的滑动,但是超出屏幕的不能显示完全,原来是它重新测量的子View,将它的height设置为,MeasureSpec.UNSPECIFIED,这个模式和At_most,exactly不一样,它不规定子View的测量,子View的测量交给他自己。

   @Override
    protected void measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) {
        ViewGroup.LayoutParams lp = child.getLayoutParams();

        int childHeightMeasureSpec;

        childHeightMeasureSpec = MeasureSpec.makeMeasureSpec( MeasureSpec.getSize(parentHeightMeasureSpec), MeasureSpec.UNSPECIFIED);

        child.measure(parentWidthMeasureSpec, childHeightMeasureSpec);
    }

这样滑动就能显示整个内容区域了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容