2 clcurie 11 clcurie_11 于 2012.11.12 17:34 提问

在Android中从URL字符串的arrayList中创建一个gridView

我想用程序的方式在Android中从URL字符串的arrayList中创建一个gridView。但是视图是以一列的形式显示的,不是网格的模式。怎么修改呢?我需要大家的帮助,谢谢!
ImageAdapter.java

public class ImageAdapter extends BaseAdapter {
    private Context mContext;
    private Serializable mThumbIds ;
    ImageDownLoader imageDownloader;
    private String img_url;
    int item_id;
    ConnectorInterface _conn=new ConnectorImpl();

    public ImageAdapter(Context c) {
        mContext = c;
    }
    public ImageAdapter(Context c,Serializable a){
        mContext=c;
        mThumbIds= a;
    }



    public int getCount() {
        return ((ArrayList<ItemEntity> )mThumbIds).size();

    }

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

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

    // create a new ImageView for each items referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = null ;
        for (int x=0;x<((ArrayList<ItemEntity>) mThumbIds).size();x++){
             imageView = new ImageView(mContext);
        if (convertView == null) {

            imageDownloader = new ImageDownLoader(imageView);

                imageDownloader.execute(((ArrayList<ItemEntity>) mThumbIds).get(x).getThumbnailImg());

                imageView.setLayoutParams(new GridView.LayoutParams(50,50));
               imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                imageView.setPadding(2,2,2,2);
                imageView.setVisibility(View.VISIBLE);

        } else {
             imageView = (ImageView) convertView;
        }
        }

        return imageView;
    }
}

1个回答

hcg_21
hcg_21   2012.11.13 09:48
已采纳

看看以下的链接,可能帮的上你:
http://www.technotalkative.com/android-gridview-example/
对于多列显示Gridview的问题,你可以在Gridview设置下列属性:

 android:numColumns="auto_fit" 
Csdn user default icon
上传中...
上传图片
插入图片