ZzImageBox
A powerful image container for adding and removing images.
傳送門:https://github.com/zhouzhuo810/ZzImageBox
功能簡介:
1.支持添加凿傅、刪除、默認(rèn)圖片的配置;
2.支持最大行數(shù)限制喇喉;
3.支持每行數(shù)量修改剪芍;
4.支持添加幽告、刪除腌且、圖片點(diǎn)擊回調(diào)接口殖属。
5.支持Box的添加(.addImage(String imagePath))和刪除(.removeImage(int position))软啼;
6.支持加載本地和網(wǎng)絡(luò)圖片(使用方法.addImage(String url)
)桑谍;
7.支持自定義圖片加載框架(使用.setOnlineImageLoader(ZzImageBox.OnlineImageLoader listener)
,
如果有網(wǎng)絡(luò)圖片必須使用此方法);
8.支持左右margin設(shè)置。
Gradle
compile 'me.zhouzhuo.zzimagebox:zz-image-box:1.0.6'
內(nèi)部依賴項(xiàng)說明:
compile 'com.android.support:recyclerview-v7:27.0.1'
也就是說添加ZzImageBox同時(shí)會(huì)添加RecyclerView包祸挪。
Maven
<dependency>
<groupId>me.zhouzhuo.zzimagebox</groupId>
<artifactId>zz-image-box</artifactId>
<version>1.0.4</version>
<type>pom</type>
</dependency>
What does it look like?
zz_image_box_demo.gif
How to use it ?
注意:
- 為了保證圖片是正方形锣披,需要保證ZzImageBox水平方向是填滿屏幕的,也就是說父容器不能有padding和margin贿条。
- ZzImageBox的marginLeft屬性使用zib_left_margin代替雹仿;
- ZzImageBox的marginRight屬性使用zib_right_margin代替;
- 如果不需要顯示添加圖片整以,可以設(shè)置zib_img_add為透明顏色胧辽;
- 加載網(wǎng)絡(luò)圖片必須添加
.setOnlineImageLoader();
方法,
在onLoadImage(ImageView iv, String url)
中自行使用Glide等框架加載公黑;
xml:
<me.zhouzhuo.zzimagebox.ZzImageBox
android:id="@+id/zz_image_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:zib_left_margin="20dp"
app:zib_right_margin="20dp"
app:zib_img_padding="5dp"
app:zib_img_size_one_line="4"
app:zib_max_line="3"
app:zib_img_deletable="true"
app:zib_img_add="@drawable/iv_add"
app:zib_img_default="@drawable/iv_default"
app:zib_img_delete="@drawable/iv_delete"
/>
java:
final ZzImageBox imageBox = (ZzImageBox) findViewById(R.id.zz_image_box);
//如果需要加載網(wǎng)絡(luò)圖片邑商,添加此監(jiān)聽摄咆。
imageBox.setOnlineImageLoader(new ZzImageBox.OnlineImageLoader() {
@Override
public void onLoadImage(ImageView iv, String url) {
Log.d("ZzImageBox", "url=" + url);
Glide.with(MainActivity.this).load(url).into(iv);
}
});
imageBox.setOnImageClickListener(new ZzImageBox.OnImageClickListener() {
@Override
public void onImageClick(int position, String filePath) {
Log.d("ZzImageBox", "image clicked:" + position + "," + filePath);
}
@Override
public void onDeleteClick(int position, String filePath) {
imageBox.removeImage(position);
Log.d("ZzImageBox", "delete clicked:" + position + "," + filePath);
Log.d("ZzImageBox", "all images\n"+imageBox.getAllImages().toString());
}
@Override
public void onAddClick() {
imageBox.addImage(null);
Log.d("ZzImageBox", "add clicked");
Log.d("ZzImageBox", "all images\n"+imageBox.getAllImages().toString());
}
});
屬性說明:
<declare-styleable name="ZzImageBox">
<attr name="zib_max_line" format="integer" />
<attr name="zib_img_size_one_line" format="integer" />
<attr name="zib_img_padding" format="dimension|reference" />
<attr name="zib_img_default" format="color|reference" />
<attr name="zib_img_delete" format="color|reference" />
<attr name="zib_img_add" format="color|reference" />
<attr name="zib_img_deletable" format="boolean" />
<attr name="zib_left_margin" format="dimension|reference" />
<attr name="zib_right_margin" format="dimension|reference" />
</declare-styleable>
屬性名 | 屬性類型 | 屬性功能 |
---|---|---|
zib_max_line | integer | 最大行數(shù) |
zib_img_size_one_line | integer | 每行數(shù)量 |
zib_img_padding | dimension | 圖片之間的間距 |
zib_img_default | drawable/color | 默認(rèn)圖片資源id |
zib_img_delete | drawable/color | 刪除圖片資源id |
zib_img_add | drawable/color | 添加圖片資源id |
zib_img_deletable | boolean | 是否顯示刪除圖片 |
zib_left_margin | dimension | 控件距離屏幕左邊距離 |
zib_right_margin | dimension | 控件距離屏幕右邊距離 |
更新日志
v1.0.6
- 支持動(dòng)態(tài)設(shè)置左間距,使用
setLeftMarginInPixel()
方法人断; - 支持動(dòng)態(tài)設(shè)置右邊距吭从,使用
setRightMarginInPixel()
方法; - 支持動(dòng)態(tài)設(shè)置圖片間距恶迈,使用
setImagePadding()
方法涩金; - 支持動(dòng)態(tài)設(shè)置單行圖片數(shù)量,使用
setImageSizeOneLine()
方法蝉绷; - 更新RecyclerView版本到
com.android.support:recyclerview-v7:27.0.1
鸭廷。
v1.0.5
- 支持加載網(wǎng)絡(luò)圖片;
v1.0.4
- 點(diǎn)擊圖片返回圖片對(duì)象熔吗,用于適應(yīng)轉(zhuǎn)場(chǎng)動(dòng)畫辆床。
v1.0.3
- 新增zib_left_margin和zib_right_margin設(shè)置左右外間距屬性。
v1.0.2
- 首次提交桅狠。
License
Copyright ? zhouzhuo810
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.