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

這樣滑動就能顯示整個內容區域了

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容