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

gridview 自适应平均android界面

时间:2015-01-26 10:20:36      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:gridview

需要重写
GridView和BaseAdapter
public class WrapGridview extends GridView{
    public WrapGridview(Context context) {
        super(context);
    }
    public WrapGridview(Context context,AttributeSet attributeSet) {
        super(context,attributeSet);
    }
    public WrapGridview(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {//这是主要代码
        int expandSpec = MeasureSpec.makeMeasureSpec(
                Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }
}

class AutAdapter extends BaseAdapter {
        private List<Map<String, Object>> autlist = AutList();

        @Override
        public int getCount() {
            return autlist.size();
        }

        @Override
        public Map<String, Object> getItem(int i) {
            return autlist.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            AutHolder autHolder = null;
            if (view == null) {
                view = View.inflate(SkillInfoActivity.this, R.layout.item_authentication, null);
                autHolder = new AutHolder();
                view.setLayoutParams(new GridView.LayoutParams(sidew, sidew));//这是主要的   控制item的大小
                autHolder.iv = (ImageView) view.findViewById(R.id.skill);
                autHolder.tv = (TextView) view.findViewById(R.id.aut);
                view.setTag(autHolder);
            } else {
                autHolder = (AutHolder) view.getTag();
            }
            Map<String, Object> autmap = getItem(i);
            autHolder.iv.setImageResource(Integer.parseInt(autmap.get("img").toString()));
            autHolder.tv.setText(autmap.get("title").toString());
            return view;
        }

    }


gridview 自适应平均android界面

标签:gridview

原文地址:http://blog.csdn.net/liuwei522176950/article/details/43148659

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