在adapter的getView中获取parent的宽高,进行设置item的宽高,为了解决第一个item的信息显示不完整,修改如下:
public View getView(final int position, View convertView, ViewGroup parent) {
Holder holder;
if(convertView == null){
convertView = mInflater.inflate(R.layout.p2v_gridview_item, parent,false);
holder = new Holder();
ViewUtils.inject(holder,convertView);
width = (parent.getWidth() -20)/3;
height = width * 3 /2 ;
//item的layoutparams用GridView.LayoutParams或者 AbsListView.LayoutParams设置,不能用LinearLayout.LayoutParams
//convertView.setLayoutParams(new GridView.LayoutParams(width,height));
convertView.setLayoutParams(new AbsListView.LayoutParams(width, height) );
convertView.setTag(holder);
}else{
holder = (Holder) convertView.getTag();
}
VodDetailBean info = list.get(position);
if (info != null) {
holder.tvRow.setText(info.getTitle());
if(info.getImg() == null)
{
holder.ivRow.setImageResource(R.drawable.ic_launcher);
}
else {
bitmapUtils.display(holder.ivRow, info.getImg());
}
}
return convertView;
}