码迷,mamicode.com
首页 > 移动开发 > 详细

android GridView网格布局,高度问题

时间:2015-01-20 12:03:52      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:android   gridview宽度   网格布局   

 项目中,遇到这样问题,

网格布局宽度自适应,但是高度设不了,文字和图片下面有一大片空白,将高度写死为306dp也不可以,

多方查找,得到答案,需要在适配器中 设置layoutparams设置高度,

代码如下


public class ServiceGridBaseAdapter extends BaseAdapter{


private Context mContext;
private List<StaffEntity> mList;
private StaffEntity entity;
 
public ServiceGridBaseAdapter() {
super();
}
 
public ServiceGridBaseAdapter(Context mContext, List<StaffEntity> mList ) {
super();
this.mContext = mContext;
this.mList = mList;
}


@Override
public int getCount() {
// TODO Auto-generated method stub
return mList.size();
}


@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return mList.get(position);
}


@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
entity = mList.get(position);
convertView = LayoutInflater.from(mContext).inflate(R.layout.item_staff_grid, null);
if(holder !=null){
holder = (ViewHolder) convertView.getTag();
} else {
holder = new ViewHolder();
holder.imageView = (ImageView)convertView.findViewById(R.id.item_service_photo);
holder.name = (TextView)convertView.findViewById(R.id.item_service_name);
holder.cell = (TextView)convertView.findViewById(R.id.item_service_cell);
   
AbsListView.LayoutParams params = new AbsListView.LayoutParams(
               android.view.ViewGroup.LayoutParams.FILL_PARENT, 306
               );
convertView.setLayoutParams(params);

    convertView.setTag(holder);
}
if(entity!=null){
holder.name.setText(entity.getName());
holder.cell.setText(entity.getTel());
// holder.imageView.setImageResource(Drawable.createFromPath(entity.getPhoto()));
}
  
return convertView;
}


class ViewHolder{

TextView name,cell;
        ImageView imageView;
}



}

android GridView网格布局,高度问题

标签:android   gridview宽度   网格布局   

原文地址:http://blog.csdn.net/kan1kan5/article/details/42914839

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!