Coder Social home page Coder Social logo

ninegridimageview's Introduction

NineGridImageView

中文版说明点我

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

Sample

Download NineGridImageView-Demo

Features

  • set gap between images

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

  • 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.0.0'
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, 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, int index, List<Photo> photoList) {
       showBigPicture(context, photoList.get(index).getBigUrl());
    }
};
        
...
	mNineGridImageView.setAdapter(mAdapter);
...
4. set pictures data to NineGridImageView
nineGridImageView.setImagesData(List<T> imageDataList);

Credits

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.

ninegridimageview's People

Watchers

Chew Chit Siang avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.