从assets文件夹中获取图像并在android中填充gridview

时间:2015-06-24 09:22:10

标签: android gridview assets

我正在开发一个小应用程序,我对android知之甚少。所以我需要你的帮助实际上我把一些大量的图像放在assets子文件夹中。现在我想要的是,我想读取我放入资产子文件夹的所有图像,例如“images”文件夹,然后我想在网格视图中填充所有图像。请各位朋友帮我在网格视图中填写图片。 我曾尝试过以下链接,但我没有从这个网站获得满意 Loading Images from assets to GridView with smooth Scrolling

3 个答案:

答案 0 :(得分:0)

我实际上在https://xjaphx.wordpress.com/2011/10/02/store-and-use-files-in-assets/

上找到了这个答案
public void loadFromAsset() {
    InputStream is = getAssets().open("filename.extension");

    //Load image as drawable
    Drawable draw = Drawable.createFromStream(is, null);

    //Once you get the drawable, set the image to imageView
    imageView.setImageDrawable(draw);
}

答案 1 :(得分:0)

然后将下面的代码粘贴到CustomAdapter GridViewAdapter

公共类GridViewAdapter扩展了BaseAdapter {

    Context context;
    int layoutResourceId;
    private ArrayList<String> griRowItems;
    LayoutInflater vi;
    ImageLoader imageLoader;
    String[] imageUrls;
    ArrayList<String> imagePath;
    DisplayImageOptions options;
    ViewHolder holder = null;

    public GridViewAdapter(Context context,
            int layoutResourceId, ArrayList<String> mApps) {
        this.context = context;
        this.griRowItems = mApps;
        this.layoutResourceId = layoutResourceId;


        imageLoader = ImageLoader.getInstance();
        this.imageLoader.init(ImageLoaderConfiguration.createDefault(context));

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        vi = (LayoutInflater) context
                .getSystemService(Service.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {
            convertView = vi.inflate(R.layout.grid_double, parent,
                    false);
            holder = new ViewHolder();
        }

        holder.imageView = (ImageView) convertView.findViewById(R.id.thumbImage);
        // holder.progressBar = (ProgressBar) convertView
        // .findViewById(R.id.progress);

        String tempStr = "assets://" +  griRowItems.get(position);
        lazyLoading(imageLoader, tempStr, holder.imageView,
                options);
        return convertView;
    }




    @Override
    public int getCount() {
        return griRowItems.size();
    }

    @Override
    public Object getItem(int position) {
        return griRowItems.get(position);
    }

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

    public static void lazyLoading(ImageLoader imageLoader, String tempStr, ImageView imageView,DisplayImageOptions options) {
        imageLoader.displayImage(tempStr, imageView, options,
                new SimpleImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String imageUri, View view) {
                    }

                    @Override
                    public void onLoadingFailed(String imageUri, View view,FailReason failReason) {
                    }

                    @Override
                    public void onLoadingComplete(String imageUri, View view,Bitmap loadedImage) {
                    }
                }, new ImageLoadingProgressListener() {
                    @Override
                    public void onProgressUpdate(String imageUri, View view,int current, int total) {
                    }
                });
    }

    static class ViewHolder {
        ImageView imageView;
        // ProgressBar progressBar;
        //TextView tvTitle;
        // DisplayImageOptions options;
    }

答案 2 :(得分:0)

公共类Flower_Mahendi扩展了活动{

var scrollingObjects = Resources.FindObjectsOfTypeAll<ScrollingBackgroundScript>();