发布后,图片闪烁

时间:2016-01-25 08:26:24

标签: android image android-layout android-fragments android-intent

我正在开发社交应用程序,它即将完成,但我遇到了一个图像闪烁的问题。当屏幕上有大约9到10张图像时,如果我滚动页面,则会发生图像闪烁。

 @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {

            LayoutInflater inf = (LayoutInflater) getApplicationContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inf.inflate(R.layout.view_explore_icon, null);
            holder = new ViewHolder();
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.back = (RelativeLayout) convertView.findViewById(R.id.back_layout);
        holder.img = (ImageView) convertView.findViewById(R.id.img_grid_album);
        convertView.setTag(holder);
        ImageLoader.getInstance().displayImage(
                Static_Urls.explore_logo_pic + categoryList.get(position).cat_logo,
                holder.img);

        if (pos == position) {
            holder.back.setBackgroundResource(R.drawable.explore_selected_image);
        } else {
            holder.back.setBackgroundResource(R.drawable.explore_blank_image);
        }
        holder.img.setTag(position);
        holder.img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                pos = (int) view.getTag();
                txt_cat_name.setText(categoryList.get(position).category);
                //notifyDataSetChanged();
                new GetAllExplorePic().execute(categoryList.get(position).id);

            }

        });

        return convertView;
    }

1 个答案:

答案 0 :(得分:0)

取代if(convertview == null)

中的以下代码行
holder.back = (RelativeLayout) convertView.findViewById(R.id.back_layout);
    holder.img = (ImageView) convertView.findViewById(R.id.img_grid_album);
    convertView.setTag(holder);

你的最终代码

    @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {

            LayoutInflater inf = (LayoutInflater) getApplicationContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inf.inflate(R.layout.view_explore_icon, null);
            holder = new ViewHolder();
            holder.back = (RelativeLayout) convertView.findViewById(R.id.back_layout);
        holder.img = (ImageView) convertView.findViewById(R.id.img_grid_album);
        convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

      //  holder.back = (RelativeLayout) convertView.findViewById(R.id.back_layout);
     //   holder.img = (ImageView) convertView.findViewById(R.id.img_grid_album);
      //  convertView.setTag(holder);
        ImageLoader.getInstance().displayImage(
                Static_Urls.explore_logo_pic + categoryList.get(position).cat_logo,
                holder.img);

        if (pos == position) {
            holder.back.setBackgroundResource(R.drawable.explore_selected_image);
        } else {
            holder.back.setBackgroundResource(R.drawable.explore_blank_image);
        }
        holder.img.setTag(position);
        holder.img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                pos = (int) view.getTag();
                txt_cat_name.setText(categoryList.get(position).category);
                //notifyDataSetChanged();
                new GetAllExplorePic().execute(categoryList.get(position).id);

            }

        });

        return convertView;
    }