Android自定義控件之圖片添加器

LauraWardel 8年前發布 | 10K 次閱讀 安卓開發 Android開發 移動開發

ZzImageBox

A powerful image container for adding and removing images.

Github傳送門: https://github.com/zhouzhuo810/ZzImageBox

功能簡介:

1.支持添加、刪除、默認圖片的配置;

2.支持最大行數限制;

3.支持每行數量修改;

4.支持添加、刪除、圖片點擊回調接口。

5.支持Box的添加(.addImage(String imagePath))和刪除(.removeImage(int position));

6.支持加載本地圖片(使用方法.addImage(String imagePath));

Gradle

(如不能使用可能是因為jcenter還沒審核完)

compile 'me.zhouzhuo.zzimagebox:zz-image-box:1.0.2'

Maven

<dependency>
  <groupId>me.zhouzhuo.zzimagebox</groupId>
  <artifactId>zz-image-box</artifactId>
  <version>1.0.2</version>
  <type>pom</type>
</dependency>

What does it look like?

zzimagebox

How to use it ?

xml:

<me.zhouzhuo.zzimagebox.ZzImageBox
        android:id="@+id/zz_image_box"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        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);
        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());
        }
    });</code></pre> 

屬性說明:

<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" />
    </declare-styleable>
屬性名 屬性類型 屬性功能
zib_max_line integer 最大行數
zib_img_size_one_line integer 每行數量
zib_img_padding dimension 圖片之間的間距
zib_img_default drawable color 默認圖片資源id
zib_img_delete drawable color 刪除圖片資源id
zib_img_add drawable color 添加圖片資源id
zib_img_deletable boolean 是否顯示刪除圖片

 

 

 

 本文由用戶 LauraWardel 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!