我有一個問題Picasso
和GridView
。有一些網址,我希望應用程序獲取它們並在GridView
中顯示它們。該清單適用於INTERNET permission
和New Activity
。Picasso和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
存在問題。
請幫忙,謝謝。
發生什麼類型的錯誤? – sasikumar
我發現,中心'centerCrop()'後面有一個必需屬性。應該是'centerCrop()。resize(int,int)' –