android底部弹出显示不全,Android 解决 NestedScrollView 底部内容被遮挡显示不全
Android 解決 NestedScrollView 底部內容被遮擋顯示不全
很早之前就遇到過在使用 NestedScrollView 的時候發現底部的 View 總是顯示不全, 看起來像是被底部的什 padding 遮擋了一樣.
這次是一個 recycleView, 在 list 沒有數據的時候總是顯示不全, 有數據的時候就正常了. 子類控件高度都設置了 wrap_content, 還是沒效果. 以前都是直接在最下面的子控件加一個合適的 layout_marginBottom.. 今天剛好比較閑就決定找到原因, 解決, 也方便以后查閱.
解決方案
NestedScrollView 加一句
Android:fillViewport="true"
完美解決哈哈
原理
出現這個問題感覺應該是 NestedScrollView 的測量方法去找原因@Override
protectedvoidonMeasure(intwidthMeasureSpec,intheightMeasureSpec){
super.onMeasure(widthMeasureSpec,heightMeasureSpec);
if(!mFillViewport){
return;
}
finalintheightMode=MeasureSpec.getMode(heightMeasureSpec);
if(heightMode==MeasureSpec.UNSPECIFIED){
return;
}
if(getChildCount()>0){
Viewchild=getChildAt(0);
finalNestedScrollView.LayoutParamslp=(LayoutParams)child.getLayoutParams();
intchildSize=child.getMeasuredHeight();
intparentSpace=getMeasuredHeight()
-getPaddingTop()
-getPaddingBottom()
-lp.topMargin
-lp.bottomMargin;
if(childSize
intchildWidthMeasureSpec=getChildMeasureSpec(widthMeasureSpec,
getPaddingLeft()+getPaddingRight()+lp.leftMargin+lp.rightMargin,
lp.width);
intchildHeightMeasureSpec=
MeasureSpec.makeMeasureSpec(parentSpace,MeasureSpec.EXACTLY);
child.measure(childWidthMeasureSpec,childHeightMeasureSpec);
}
}
}
看到這里, mFillViewport, 字面意思填充, 如果是 false 被 return 出去,if(!mFillViewport){
return;
}```
看文檔說明/**
* When set to true, the scroll view measure its child to make it fill the currently
* visible area.
*/
privatebooleanmFillViewport;
翻譯過來
設置為 true 時, 滾動視圖將測量其子級以使其填充當前 * 可見區域.
默認值為 false, 果然沒有重新測量 , 所以在 xml 添加設置為 true 就解決了
來源: https://blog.csdn.net/qq_39178733/article/details/105391159
總結
以上是生活随笔為你收集整理的android底部弹出显示不全,Android 解决 NestedScrollView 底部内容被遮挡显示不全的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ddr3服务器内存条维修,详解服务器中内
- 下一篇: java struct工作原理_Stru