GridView顯示不完全--->解決方法
1.用RecyclerView
2.自定義GridView,重寫onMeasure()方法
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
選用解決方法2然后會(huì)發(fā)現(xiàn)GridView 在當(dāng)前界面中(只要有一部分在屏幕中即會(huì)觸發(fā))導(dǎo)致 ScrollView根據(jù)GridView位置發(fā)生相對(duì)滾動(dòng)--->解決方案
1.topView.requestFocus();//頂部view獲取焦點(diǎn)
2.gridView.setFocusable(false); //讓GridView不能獲得焦點(diǎn)(xml中設(shè)置無效)
3.scrollView.scrollTo(0,0)//注意使用時(shí)機(jī),感覺很傻直接沒試
原因應(yīng)該是
scrollToChild根據(jù)computeScrollDeltaToGetChildRectOnScreen的返回值來計(jì)算滾動(dòng)的位置
重載computeScrollDeltaToGetChildRectOnScreen讓其返回0 會(huì)導(dǎo)致ScrollView內(nèi)布局產(chǎn)生變化時(shí),不能正確滾動(dòng)到focus child位置
當(dāng)然你不需要這個(gè)功能的話 重載computeScrollDeltaToGetChildRectOnScreen也可以
computeScrollDeltaToGetChildRectOnScreen大致是 根據(jù)當(dāng)前 scrollY和focus child 的 rect.bottom 去計(jì)算要滾到哪