2015-08-14 69 views
-1

我有一個問題PicassoGridView。有一些網址,我希望應用程序獲取它們並在GridView中顯示它們。該清單適用於INTERNET permissionNew ActivityPicasso和GridView的問題

這裏是activity_gallery.xml

<GridView xmlns:android='http://schemas.android.com/apk/res/android' 
android:id="@+id/gridView" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:columnWidth="90dp" 
android:numColumns="auto_fit" 
android:verticalSpacing="10dp" 
android:horizontalSpacing="10dp" 
android:stretchMode="columnWidth" 
android:layout_gravity="center" 
/> 

這裏是我GalleryActivity

public class GalleryActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_gallery); 

    GridView gridview = (GridView) findViewById(R.id.gridView); 
    gridview.setAdapter(new ImageAdapter(this)); 

    } 
} 

Adapter這是ImageAdapter

public class ImageAdapter extends BaseAdapter { 
private Context mContext; 

public ImageAdapter(Context c) { 
    mContext = c; 
} 

public int getCount() { 
    return mThumbIds.length; 
} 

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

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

public View getView(int position, View convertView, ViewGroup parent) { 
    ImageView imageView; 
    if (convertView == null) { 
     imageView = new ImageView(mContext); 
     imageView.setLayoutParams(new GridView.LayoutParams(200, 200)); 
    } else { 
     imageView = (ImageView) convertView; 
    } 



    Log.i("milad", "Before"); 
    Picasso.with(mContext).load(mThumbIds[position]).centerCrop().into(imageView); 
    Log.i("milad", "After"); 
    return imageView; 

} 

String[] mThumbIds = 
     {"http://30shahid.ir/Upload/pictures/gallery/2015/08/11/IMG_4995_e.jpg", 
     "http://30shahid.ir/Upload/pictures/gallery/2015/08/11/IMG_502kkk7.jpg", 
     "http://30shahid.ir/Upload/pictures/gallery/2015/08/11/IMG_49o74.jpg", 
     "http://30shahid.ir/Upload/pictures/gallery/2015/08/11/13940515184958618_PhotoL.jpg", 
     }; 
} 

我的代碼中提到,我得到兩個日誌: Picasso.with(mContext).load(mThumbIds[0]).centerCrop().into(imageView);
我得到Before登錄LOGCAT,但沒有After登錄。這意味着Picasso Line存在問題。
請幫忙,謝謝。

+0

發生什麼類型的錯誤? – sasikumar

+0

我發現,中心'centerCrop()'後面有一個必需屬性。應該是'centerCrop()。resize(int,int)' –

回答

0

我猜您有在GridView控件lodding圖像的問題最近我曾與通用的圖像加載庫

private static class ImageAdapter extends BaseAdapter { 
    private final String[] IMAGE_URLS ; 

    private LayoutInflater inflater; 

    private DisplayImageOptions options; 

    ImageAdapter(Context context,String source[]) { 
     inflater = LayoutInflater.from(context); 
     IMAGE_URLS=source; 

     options = new DisplayImageOptions.Builder() 
       .showImageOnLoading(R.mipmap.ico_place_holder) 
       .showImageForEmptyUri(R.drawable.ic_empty) 
       .showImageOnFail(R.drawable.ic_error) 
       .cacheInMemory(true) 
       .cacheOnDisk(true) 
       .considerExifParams(true) 
       .bitmapConfig(Bitmap.Config.RGB_565) 
       .build(); 
    } 



    @Override 
    public int getCount() { 
     return IMAGE_URLS.length; 
    } 

    @Override 
    public Object getItem(int position) { 
     return null; 
    } 

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

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     final ViewHolder holder; 
     View view = convertView; 
     if (view == null) { 
      view = inflater.inflate(R.layout.item_grid_image, parent, false); 
      holder = new ViewHolder(); 
      assert view != null; 
      holder.imageView = (ImageView) view.findViewById(R.id.image); 
      holder.progressBar = (ProgressBar) view.findViewById(R.id.progress); 
      view.setTag(holder); 
     } else { 
      holder = (ViewHolder) view.getTag(); 
     } 

     ImageLoader.getInstance() 
       .displayImage(IMAGE_URLS[position], holder.imageView, options, new SimpleImageLoadingListener() { 
        @Override 
        public void onLoadingStarted(String imageUri, View view) { 
         holder.progressBar.setProgress(0); 
         holder.progressBar.setVisibility(View.VISIBLE); 
        } 

        @Override 
        public void onLoadingFailed(String imageUri, View view, FailReason failReason) { 
         holder.progressBar.setVisibility(View.GONE); 
        } 

        @Override 
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { 
         holder.progressBar.setVisibility(View.GONE); 
        } 
       }, new ImageLoadingProgressListener() { 
        @Override 
        public void onProgressUpdate(String imageUri, View view, int current, int total) { 
         holder.progressBar.setProgress(Math.round(100.0f * current/total)); 
        } 
       }); 

     return view; 
    } 
} 

static class ViewHolder { 
    ImageView imageView; 
    ProgressBar progressBar; 
} 

工作也許這會幫助你。 享受編碼。

+0

我發現中心centerCrop()後有一個必需的屬性。應該是centerCrop()。resize(int,int)...通過感謝很多@Nawaf –