Gridview height gets cut

后端 未结 6 1557
刺人心
刺人心 2020-11-22 17:26

I\'m trying to display 8 items inside a gridview. Sadly, the gridview height is always too little, so that it only shows the first row, and a little part of the second.

6条回答
  •  清歌不尽
    2020-11-22 17:28

    Just calculate the height for AT_MOST and set to on measure. Here GridView Scroll will not work so. Need to use Vertical Scroll View explicitly.

     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         int heightSpec;
    
         if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {
    
             heightSpec = MeasureSpec.makeMeasureSpec(
                            Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
         }
         else {
             // Any other height should be respected as is.
             heightSpec = heightMeasureSpec;
         }
    
         super.onMeasure(widthMeasureSpec, heightSpec);
     }
    

提交回复
热议问题