Android自定义控件之图片添加器
LauraWardel
8年前
<h2><strong>ZzImageBox</strong></h2> <p>A powerful image container for adding and removing images.</p> <h3>Github传送门: <a href="/misc/goto?guid=4959719793651006168" rel="nofollow,noindex">https://github.com/zhouzhuo810/ZzImageBox</a></h3> <h3><strong>功能简介:</strong></h3> <p>1.支持添加、删除、默认图片的配置;</p> <p>2.支持最大行数限制;</p> <p>3.支持每行数量修改;</p> <p>4.支持添加、删除、图片点击回调接口。</p> <p>5.支持Box的添加(.addImage(String imagePath))和删除(.removeImage(int position));</p> <p>6.支持加载本地图片(使用方法.addImage(String imagePath));</p> <h3>Gradle</h3> <p>(如不能使用可能是因为jcenter还没审核完)</p> <pre> <code class="language-java">compile 'me.zhouzhuo.zzimagebox:zz-image-box:1.0.2'</code></pre> <h3><strong>Maven</strong></h3> <pre> <code class="language-java"><dependency> <groupId>me.zhouzhuo.zzimagebox</groupId> <artifactId>zz-image-box</artifactId> <version>1.0.2</version> <type>pom</type> </dependency></code></pre> <h2><strong>What does it look like?</strong></h2> <p style="text-align:center"><img src="https://simg.open-open.com/show/04382da5e8ae6fac2a7aff02edccd779.gif"></p> <p style="text-align:center">zzimagebox</p> <h2><strong>How to use it ?</strong></h2> <p>xml:</p> <pre> <code class="language-java"><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" /></code></pre> <p>java:</p> <pre> <code class="language-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> <h2><strong>属性说明:</strong></h2> <pre> <code class="language-java"><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></code></pre> <table> <thead> <tr> <th>属性名</th> <th>属性类型</th> <th>属性功能</th> </tr> </thead> <tbody> <tr> <td>zib_max_line</td> <td>integer</td> <td>最大行数</td> </tr> <tr> <td>zib_img_size_one_line</td> <td>integer</td> <td>每行数量</td> </tr> <tr> <td>zib_img_padding</td> <td>dimension</td> <td>图片之间的间距</td> </tr> <tr> <td>zib_img_default</td> <td>drawable</td> <td>color</td> <td>默认图片资源id</td> </tr> <tr> <td>zib_img_delete</td> <td>drawable</td> <td>color</td> <td>删除图片资源id</td> </tr> <tr> <td>zib_img_add</td> <td>drawable</td> <td>color</td> <td>添加图片资源id</td> </tr> <tr> <td>zib_img_deletable</td> <td>boolean</td> <td>是否显示删除图片</td> </tr> </tbody> </table> <p> </p> <p> </p> <p> </p>