【问题标题】:background image of a row in a listview列表视图中一行的背景图像
【发布时间】:2012-12-26 11:58:09
【问题描述】:

我有一个列表视图,它显示来自互联网的图像和文本。 我的意图是这个图像,除了显示一个图像视图,是列表视图行的背景图像。 这可行,但有问题。

在我为图像视图准备的列表视图适配器中:

imageLoader.DisplayImage (song.get (principal.KEY_PICTURE) my_imageView);

并在 LinearLayout 中使用图像:

imageLoader.DisplayImageLinear (song.get (principal.KEY_PICTURE) my_linearLayout);

这会调用以下方法:

public void DisplayImageLinear (String url, LinearLayout linearbck)
{
Bitmap bitmap = memoryCache.get (url);
Drawable d = new BitmapDrawable (bitmap);
if (bitmap! = null) {
linearbck (d);
}
else
{ linearbck.setBackgroundResource (R.drawable.list_selector); }
}

我的问题是listview的行的背景图片只有在listview滑出屏幕并重新进入时才可见...

我希望我的解释正确..这里有一张解释问题的图片

我尝试使用linearbck.invalidate(),但是没有成功

我真诚地感谢任何帮助

谢谢

最好的问候

编辑:

添加适配器。谢谢:)

public class lstAdapter extends BaseAdapter {

    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 

    public MinAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }


    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;


        if(convertView==null)
            vi = inflater.inflate(R.layout.list_row, null);


        ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); 
        ImageView photo_user =(ImageView)vi.findViewById(R.id.photoUser); 
        LinearLayout background =(LinearLayout)vi.findViewById(R.id.background);

        HashMap<String, String> song = new HashMap<String, String>();
        song = data.get(position);


        imageLoader.DisplayImage(song.get(principal.KEY_AVATAR_AUTOR_ENTRADA), thumb_image);
        imageLoader.DisplayImage(song.get(principal.KEY_PICTURE), photo_user);
        imageLoader.DisplayImageLinear(song.get(principal.KEY_PICTURE), background);


        return vi;
    }

    @Override 
    public boolean isEnabled(int position) 
    { 
        if(principal.asynTaskEnUso.equals("yes")){ 
            return false; 
        } else { 
            return true; 
        } 

    } 

}

【问题讨论】:

  • 您可以粘贴适配器的代码吗?可能是您遗漏了与 convertview 相关的内容..
  • 是的,发布更多细节的代码
  • 当然,添加适配器。谢谢

标签: android listview bitmap drawable


【解决方案1】:

当我们看到source of ImageLoader时,当缓存中没有下载照片时,它会将照片排队。

=> 你没有在排队拍照。

当照片下载时,是set to the ImageView,来自回调。

=>您可能(或很可能)没有将其设置为 LinearLayout 作为背景。

现在你的问题:

我的问题是列表视图的行的背景图像 仅当列表视图滑出屏幕和行时可见 重新输入...

第一次,缓存是空的,它没有找到需要的照片,所以它去下载它,因为你还没有实现和排队等待LinearLayout在回调中设置为背景。它没有显示,但是当您滚动 ListView 并返回时,它会第一次找到图像(因为它已下载并缓存)并将其设置为背景。

解决方案:

维护并设置一些标志以跟踪您的 LinearLayout 的引用,并在下载完成时将其设置为背景。

【讨论】:

    猜你喜欢
    • 2015-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    • 2018-12-23
    • 2015-07-04
    • 1970-01-01
    相关资源
    最近更新 更多