why931022
三非_程序猿
采纳率33.3%
2017-01-06 08:00 阅读 865

GridView设置Item自适应高度后丢失第一项

getView设置为下面这样,但是运行后丢失第一项,而且只能向上滑动,而且无法显示新的Item
请问这是为什么?

    @Override
        public View getView(int position, View convertView, ViewGroup parent){
            MyListener myListener = new MyListener(position);
            if (convertView == null){
                convertView = mInflater.inflate(R.layout.order_list_item, null);
                int iHeight = lvRight.getHeight();
                int iWidth = lvRight.getWidth();
                GridView.LayoutParams params = new GridView.LayoutParams(iWidth / 3,
                        iHeight /3);
                convertView.setLayoutParams(params);
                holder = new Holder();
                holder.foodAmountAdd = (Button)convertView.findViewById(R.id.food_amount_add) ;
                holder.fooodPhoto = (ImageView)convertView.findViewById(R.id.food_photo);
                holder.maleDescribe = (TextView)convertView.findViewById(R.id.food_describe);
                holder.maleDescribe.getBackground().setAlpha(204);
                convertView.setTag(holder);
            }else {
                holder = (Holder) convertView.getTag();
            }
            holder.foodAmountAdd.setOnClickListener(myListener);
            return convertView;
        }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • sxt_zls 狗屎糖 2017-01-06 09:00

    你的myLitener是什么? 自定义的点击事件呀?

          int iHeight = lvRight.getHeight();
      int iWidth = lvRight.getWidth();
    
            这两行代码 你确定能拿到 宽高???
    
    点赞 评论 复制链接分享
  • jamyeson jamyeson 2017-01-06 11:34

    获取宽高得需要WindowManager对象

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    int iWidth = wm.getDefaultDisplay().getWidth();
    int iHeight =wm.getDefaultDisplay().getHeight();

    点赞 评论 复制链接分享

相关推荐