Similar to QQ space, wechat circle of friends, Weibo home page, show pictures of the nine grid control, automatically according to the number of pictures to determine the size of the picture and control size, using Adapter mode to set pictures, external interface callback, Using the interface to load images, support arbitrary loading frame images, such as the Glide, ImageLoader, Fresco, xUtils3, Picasso was, etc., a larger support click the full screen preview images

usage

For Android Studio users, you can add:

The compile 'com. Lzy. Widget: ninegridview: 0.2.0'Copy the code

Or use

    compile project(':ninegridview')Copy the code

2. Project functions

When the number of pictures is only one, automatically adjust the size of the control according to the size of the picture. By default, click the full screen preview effect. With the image preview animation using the interface, support arbitrary loading frame images, such as the Glide, ImageLoader, Fresco, xUtils3, Picasso was such as integrated PhotoView preview using interfaces take pictures of loading way, Can easily replace Glide into their favorite ImageLoader support fill a grid two display mode when the number of pictures to obtain more than the maximum number of pictures displayed, the last picture will show the remaining number (similar to QQ dynamic effect) using simple code, Only need a few lines of code other features added in…… 3. Parameter Meaning

Custom attribute Name Parameter Meaning ngv_singleImageSize Maximum image size when only one image is displayed ngv_singleImageRatio Width to height Ratio when only one image is displayed ngv_gridSpacing Spacing when only one image is displayed in the grid By default, 3DP ngv_maxSize specifies the maximum number of images to display. By default, the maximum number of images to display is 9. Ngv_mode Supports two display modes: Fill and Grid. Code demo

1. Initialize the NineGridView image loader in Application

    NineGridView.setImageLoader(new PicassoImageLoader());

    /** Picasso 加载 */
    private class PicassoImageLoader implements NineGridView.ImageLoader {

        @Override
        public void onDisplayImage(Context context, ImageView imageView, String url) {
            Picasso.with(context).load(url)//
                    .placeholder(R.drawable.ic_default_image)//
                    .error(R.drawable.ic_default_image)//
                    .into(imageView);
        }

        @Override
        public Bitmap getCacheImage(String url) {
            return null;
        }
    }Copy the code

2. Initialize NineGridView’s Adapter in your own Adapter

ImageInfo is a data Bean provided in the library. Two urls are required, representing the small image and the large image URL respectively. If there is no large image or small image, they are assigned to the same URL. ClickNineGridViewAdapter is the default ClickNineGridViewAdapter provided by the library. If you do not want to use the preview effect, you can inherit the NineGridViewAdapter and implement the onDisplayImage method.

ArrayList<ImageInfo> imageInfo = new ArrayList<>(); List<EvaluationPic> imageDetails = item.getAttachments(); if (imageDetails ! = null) { for (EvaluationPic imageDetail : imageDetails) { ImageInfo info = new ImageInfo(); info.setThumbnailUrl(imageDetail.smallImageUrl); info.setBigImageUrl(imageDetail.imageUrl); imageInfo.add(info); } } holder.nineGrid.setAdapter(new ClickNineGridViewAdapter(context, imageInfo));Copy the code