A custom widget for Android, which used for showing grid pictures.
This is a custom widget for Android, which uesd for showing grid pictures, such as you seeing in weibo or wechat.
1.1.1
1.1.0
NineGridImageViewAdapter
's onItemImageClick()
method, providing clicked ImageViewsetItemImageClickListener()
method1.0.3
fix return data not original bug
1.0.2
1.0.1
1.0.0
first publish
Download NineGridImageView-Demo
set gap between images
app:imgGap="4dp"
or nineGridImageView.setGap(int gap);
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)
compile 'com.jaeger.ninegridimageview:library:1.1.1'
<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"/>
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;
}
}
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
.onItemImageClick(Context context, int index, List<T> list)
method, it is easy to handle image click event.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);
...
nineGridImageView.setImagesData(List<T> imageDataList);
mNineImageView.setItemImageClickListener(new ItemImageClickListener<String>() {
@Override
public void onItemImageClick(Context context, ImageView imageView, int index, List<String> list) {
}
});
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.