美文网首页
scrollview分析

scrollview分析

作者: popli | 来源:发表于2017-10-07 22:39 被阅读5次

    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);
        }
    
    

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

    相关文章

      网友评论

          本文标题:scrollview分析

          本文链接:https://www.haomeiwen.com/subject/mahsyxtx.html