位图图像保持闪烁

时间:2015-04-08 12:22:30

标签: android bitmap

我正在从json取出的图像不断闪烁,不断变得可见和不可见。这是位图的代码:

  private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
    ImageView bmImage;
    Activity mActivity;
    ProfilCustomListAdapter adapter;

    public DownloadImageTask(ImageView bmImage, Activity activity, ProfilCustomListAdapter adapter) {
        this.bmImage = bmImage;
        mActivity = activity;
        this.adapter = adapter;
    }

    protected Bitmap doInBackground(String... urls) {

        String urldisplay = urls[0];
        Bitmap mIcon11 = null;
        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            mIcon11 = BitmapFactory.decodeStream(in);
            return mIcon11;
        }
        catch (  MalformedURLException e) {
            e.printStackTrace();
            return null;
        }
        catch (  IOException e) {
            e.printStackTrace();
            return null;
        }

    }

    protected void onPostExecute(Bitmap result) {

        if(bmImage!=null)
            bmImage.setImageBitmap(result);

    }

}

CustomAdapter的代码:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    //return super.getView(position, convertView, parent);
    View view=convertView;
    if(view==null){
        holder=new ViewHolder();
        view=inflater.inflate(Resource,null);

        holder.person1TextView=(TextView)view.findViewById(R.id.textView1);
        holder.person2TextView=(TextView)view.findViewById(R.id.textView2);
        holder.person3TextView=(TextView)view.findViewById(R.id.textView3);
        holder.person4TextView=(TextView)view.findViewById(R.id.textView4);
        holder.person5TextView=(TextView)view.findViewById(R.id.textView5);
        holder.person6TextView=(TextView)view.findViewById(R.id.textView6);

        holder.arrow2ImageView=(ImageView)view.findViewById(R.id.arrow2ImageView);
        holder.arrow3ImageView=(ImageView)view.findViewById(R.id.arrow3ImageView);
        holder.arrow4ImageView=(ImageView)view.findViewById(R.id.arrow4ImageView);
        holder.arrow5ImageView=(ImageView)view.findViewById(R.id.arrow5ImageView);

        view.setTag(holder);

    }
    else {

        holder=(ViewHolder)view.getTag();
    }
new DownloadImageTask(holder.arrow2ImageView, activity,this).execute(connectionsArrayList.get(position).getArrowImage2());
return view;
}

代码有什么问题吗?请帮忙

1 个答案:

答案 0 :(得分:0)

我认为位图的大小更大,尝试重新调整大小并压缩它然后将其设置为imageview