android解决gridview只显示一半

针对GridView在ScrollView中仅显示一半的问题,通过重写GridView并调整onMeasure方法来确保所有内容均可正常展示。
   gridview在ScrollView中使用 android:layout_height="wrap_content"  发现并没有显示全部,而只是显示了一半。为了解决这个问题,打算重写了GridView。

       

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. public class MyGridView extends GridView{  
  2.   
  3.     public MyGridView(Context context, AttributeSet attrs) {       
  4.         super(context, attrs);       
  5.     }       
  6.       
  7.     public MyGridView(Context context) {       
  8.         super(context);       
  9.     }       
  10.       
  11.     public MyGridView(Context context, AttributeSet attrs, int defStyle) {       
  12.         super(context, attrs, defStyle);       
  13.     }       
  14.       
  15.     @Override       
  16.     public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {       
  17.       
  18.         int expandSpec = MeasureSpec.makeMeasureSpec(       
  19.                 Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);       
  20.         super.onMeasure(widthMeasureSpec, expandSpec);       
  21.     }       
  22. }  
在layout文件下

 

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <com.sg.zfcapp.ui.MyGridView  
  2.     android:id="@+id/gv_type"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="wrap_content"  
  5.     android:layout_marginLeft="5dip"  
  6.     android:layout_marginRight="5dip"  
  7.     android:horizontalSpacing="2.5dip"  
  8.     android:numColumns="4"  
  9.     android:verticalSpacing="2.5dip" />  
  10. /LinearLayout>  
如此就可以解决Gridview只显示一半的问题
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值