本文介绍了在自定义网格视图实现毕加索库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网格视图碎片,我要保持我的图片在应用程序中。但性能差,速度慢。而且我听说毕加索库可提高性能很多。我试图下载Picasso_sample文件夹,并在我的日食,在那里每次我Picasso.jar文件添加到我的项目运行它,我的项目崩溃和显示几个错误。我试图清理并重新构建它,但不成功。谁能帮我在建议的方式毕加索库添加到我的项目?

I have fragments with grid view and I want to keep my images in the application. But the performance is bad and slow. And I heard that Picasso library can increase the performance a lot. I tried to download the Picasso_sample folder and run it in my eclipse, where each time I add Picasso.jar file to my project, my project crashes and displays several errors. I tried to clean it and build it again, but in vain. Can anyone help me in suggesting a way to add Picasso library to my project?

下面是我有网格视图活动的code:

Here is the code of the activity that i has the grid view:

public class AndroidGridLayoutActivity extends Activity {




    public Integer[] mThumbIds = { R.drawable.rom_1, R.drawable.rom_2,
                R.drawable.rom_3, R.drawable.rom_4, R.drawable.rom_5,
                R.drawable.rom_6, R.drawable.rom_7, R.drawable.rom_8,
                R.drawable.rom_9, R.drawable.rom_10, R.drawable.rom_11,
                R.drawable.rom_12, R.drawable.rom_13, R.drawable.rom_14,
                R.drawable.rom_15, R.drawable.rom_16 };

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.grid_layout);



            GridView gridView = (GridView) findViewById(R.id.grid_view);
            try {
                // Instance of ImageAdapter Class
                gridView.setAdapter(new ImageAdapter(this, mThumbIds));
            } catch (OutOfMemoryError E) {
                E.printStackTrace();
            }

            /**
             * On Click event for Single Gridview Item
             * */
            gridView.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View v,
                        int position, long id) {

                    // Sending image id to FullScreenActivity
                    Intent i = new Intent(getApplicationContext(),
                            FullImageActivity2.class);
                    // passing array index
                    // i.putExtra("id", position);
                     i.putExtra("id", mThumbIds[position]);
                    Log.d("ID", "" + mThumbIds[position]);
                     startActivity(i);
                }
            });
        }

和这里是图像适配器的code:

and here is the code of the image adapter :

public class ImageAdapter extends BaseAdapter {
    private Context mContext;


    // Keep all Images in array
    public Integer[] mThumbIds = {};


    public ImageAdapter(Context c,Integer[] mThumbIds2){
        mContext = c;
        this.mThumbIds=mThumbIds2;
    }


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

    @Override
    public Object getItem(int position) {
        return mThumbIds[position];
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {         
        ImageView imageView = new ImageView(mContext);
        imageView.setImageResource(mThumbIds[position]);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setLayoutParams(new GridView.LayoutParams(100, 100));

        return imageView;
    }
}

凭什么我用毕加索库吗?

so how can i use Picasso library here?

推荐答案

添加毕加索的jar到libs文件夹,并尝试低于code显示

add your picasso jar into libs folder and try below code to display

Picasso.with(getApplicationContext()).load(R.drawable.ic_launcher).into(target);

链接:

这篇关于在自定义网格视图实现毕加索库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 07:48