0
我設置了我的圖像查看3210,my layout height to wrapcontent
。 imageview的圖像通過url加載。發生的事情是,當我繪製視圖的時候,由於圖像尚未加載,它只會繪製layout_width
。但在圖像已經加載時,高度不再繪製,因此不會顯示圖像。它只會顯示,如果我來回滾動,因爲,我想那是視圖將重繪的時間。有什麼辦法可以解決這個問題嗎?使用invalidate()
沒有工作。也許我做錯了嗎?Android - 即使已加載圖像也不會顯示
我會剛剛發佈的我的代碼片段: 這是getView
的MyAdapter延伸BaseAdapter:
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder = null;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
Typeface typeFaceMyriadReg = Typeface.createFromAsset(context.getAssets(), MYRIAD_REG);
if(convertView == null){
convertView = inflater.inflate(R.layout.shop_list_layout, null);
holder = new ViewHolder();
holder.txtShopName = (TextView) convertView.findViewById(R.id.name);
holder.txtShopName.setTypeface(typeFaceMyriadReg);
holder.txtShopDesc = (TextView) convertView.findViewById(R.id.desc);
holder.txtShopDesc.setTypeface(typeFaceMyriadReg);
holder.imageView = (ImageView) convertView.findViewById(R.id.prof_pic);
holder.progBar = (ProgressBar) convertView.findViewById(R.id.img_progress);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
imageLoader=new ImageLoader(context.getApplicationContext(), holder.progBar);
ShopRowItem shopItem = (ShopRowItem) getItem(position);
holder.txtShopName.setText(shopItem.getShopName());
holder.txtShopDesc.setText(shopItem.getShopDesc());
imageLoader.DisplayImage(shopItem.getImageUrl(), holder.imageView);
return convertView;
}
那麼ImageLoder的一部分:
public void DisplayImage(String url, ImageView imageView)
{
imageViews.put(imageView, url);
Bitmap bitmap=memoryCache.get(url);
if(bitmap!=null){
imageView.setImageBitmap(bitmap);
progressBar.setVisibility(View.VISIBLE);
}
else
{
queuePhoto(url, imageView);
progressBar.setVisibility(View.VISIBLE);
}
}
// ...
// ...
//Used to display bitmap in the UI thread
class BitmapDisplayer implements Runnable
{
Bitmap bitmap;
PhotoToLoad photoToLoad;
public BitmapDisplayer(Bitmap b, PhotoToLoad p){bitmap=b;photoToLoad=p;}
public void run()
{
if(imageViewReused(photoToLoad))
return;
if(bitmap!=null){
//should i do recalculations and adjustments here? ? ?
photoToLoad.imageView.setImageBitmap(bitmap);
progressBar.setVisibility(View.GONE);
}
else{
photoToLoad.imageView.setImageResource(stub_id);
progressBar.setVisibility(View.VISIBLE);
}
}
}