Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
N

NineGridImageView

> 编程语言
Open source

A custom widget for Android, which used for showing grid pictures.

1.4K stars0 likes0 views
WebsiteGitHub

About

A custom widget for Android, which used for showing grid pictures.

NineGridImageView

中文版说明点我

This is a custom widget for Android, which uesd for showing grid pictures, such as you seeing in weibo or wechat.

Update Log

  • 1.1.1

    • add longClickListener method
  • 1.1.0

    • modify NineGridImageViewAdapter 's onItemImageClick() method, providing clicked ImageView
    • add setItemImageClickListener() method
  • 1.0.3

    fix return data not original bug

  • 1.0.2

    • remove support library
  • 1.0.1

    • bug fix: if no image data or images size is zero, this view will not show;
    • add set max size of images method;
  • 1.0.0

    first publish

Sample

Download NineGridImageView-Demo

Features

  • set gap between images

    app:imgGap="4dp" or nineGridImageView.setGap(int gap);

    • set max size of images()

    app:maxSize="9" or nineGridImageView.setMaxSize(int maxSize);

    if maxSize Less than or equal to 0, there may not limit for images size.

  • set style

    app:showStyle="fill" or nineGridImageView.setShowStyle(int style);

    default style is STYLE_GRID:

    another style is STYLE_FILL:

  • when only one image, you can set it's size by:

    app:singleImgSize="120dp" or nineGridImageView.setSingleImgSize(int singleImgSize)

Usage

1. Add the dependencies to your build.gradle file, NineGridImageView is avaiable in JCenter:
compile 'com.jaeger.ninegridimageview:library:1.1.1'
2. Add the NineGridImageView to your layout XML:
<com.jaeger.ninegridimageview.NineGridImageView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="wrap_content"
    android:layout_margin="16dp"
    android:layout_width="match_parent"
    app:imgGap="4dp"
    app:showStyle="fill"
    app:singleImgSize="120dp"/>
3. set a NineGridImageViewAdapter for NineGridImageView
nineGridImageView.setAdapter(nineGridViewAdapter);

Here is NineGridImageViewAdapter.class source code: ​

public abstract class NineGridImageViewAdapter<T> {

    protected abstract void onDisplayImage(Context context, ImageView imageView, T t);

    protected void onItemImageClick(Context context, ImageView imageView, int index, List<T> list) {
    
    }

    protected ImageView generateImageView(Context context) {
        GridImageView imageView = new GridImageView(context);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        return imageView;
    }
}			
  • T is your image data model, you can simple use String or your own model
  • you must override onDisplayImage(Context context, ImageView imageView, T t) method to set load image way, you can use Picasso, Glide or ImageLoader etc, and you can also set place holder for ImageView.
  • if you need handle image click event, you can override onItemImageClick(Context context, int index, List<T> list) method, it is easy to handle image click event.
  • if you want to customize ImageView, you can override generateImageView(Context context) method, to generate your custom ImageView.

Here is sample code: ​

private NineGridImageViewAdapter<Photo> mAdapter = new NineGridImageViewAdapter<Photo>() {
	@Override
	protected void onDisplayImage(Context context, ImageView imageView, Photo photo) {
		Picasso.with(context)
		    .load(photo.getSmallUrl)
		    .placeholder(R.drawable.ic_default_image)
		    .into(imageView);
    }

    @Override
    protected ImageView generateImageView(Context context) {
        return super.generateImageView(context);
    }

    @Override
    protected void onItemImageClick(Context context, ImageView imageView, int index, List<Photo> photoList) {
       showBigPicture(context, photoList.get(index).getBigUrl());
    }
};
        
...
	mNineGridImageView.setAdapter(mAdapter);
...
4. set pictures data for NineGridImageView
nineGridImageView.setImagesData(List<T> imageDataList);
5. set ItemImageClickListener for NineGridImageView
mNineImageView.setItemImageClickListener(new ItemImageClickListener<String>() {
    @Override
    public void onItemImageClick(Context context, ImageView imageView, int index, List<String> list) {

    }
});

Credits

  • panyiho/NineGridView
  • w4lle/NineGridView

License

Copyright 2016 Jaeger Chen

Licensed under the Apache License, Version 2.0 (the "License");	you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

​ ​ ​

GitHub Issues· 31 open

View all on GitHub
  • #55

    大佬,项目怎么不维护了啊

    Updated Feb 15, 2024
  • #54

    希望迁移到maven,jcenter已跑路

    Updated May 7, 2021
  • #53

    一行能不能显示4张图?怎么修改

    Updated Apr 16, 2021
  • #52

    您好:请问添加或者删除图片的时候怎么处理?

    Updated May 8, 2020
  • #49

    requestLayout() improperly called by com.jaeger.ninegridimageview.GridImageView

    Updated Nov 29, 2019
  • #51

    关于 使用 Glide 用了 placeholder 死循环解决方案

    Updated Oct 17, 2019
  • #50

    项目还在维护么

    Updated Apr 18, 2019
  • #39

    请问能设置成圆角图片吗?我用glide设置圆角没反应

    Updated Feb 28, 2019
  • #23

    我用baserecyclerviewadapterhelper适配时,引用此控件,在6.0系统上 报ninegridview.GridImageView{c03dd20 V.ED..C.. ......ID 0,312-300,612} during layout: running second layout pass

    Updated Dec 27, 2018
  • #33

    如果图片地址错误,设置一个错误显示的位图,会导致```onDisplayImage```不停重复调用

    Updated Dec 25, 2018

Highlights

  • •add longClickListener method
  • •modify NineGridImageViewAdapter 's onItemImageClick() method, providing clicked ImageView
  • •add setItemImageClickListener() method
  • •remove support library
  • •bug fix: if no image data or images size is zero, this view will not show;
  • •add set max size of images method;
  • •set gap between images
  • •set max size of images()
  • •set style
  • •when only one image, you can set it's size by:

> Tags

Javaandroidcustom-widgetninegridviewshowing-grid-pictures

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言