Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

simplepeng/AddImageView

Open more actions menu

Repository files navigation

AddImageView

选择照片的自定义九宫格View,扩展性极高。

  • 支持自定义视图
  • 支持九宫格显示(设置maxCount)
  • 支持拖拽排序(有震动和动画,可以关闭)
  • 支持每行item个数设置
  • 等等
静态图 动态图

导入依赖

maven { url 'https://jitpack.io' }
implementation 'com.github.simplepeng:AddImageView:v1.0.2'

如何使用

在布局中添加me.simple.view.AddImageView

<me.simple.view.AddImageView
        android:id="@+id/addImageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

在代码中注册ItemViewDelegateAddViewDelegate,默认也有实现类。

/**
 * 注册ItemView的代理
 */
addImageView.registerItemViewDelegate(CustomItemView())
/**
 * 注册AddView的代理
 */
addImageView.registerAddViewDelegate(CustomAddView())
class CustomItemView : AddImageView.ItemViewDelegate<CustomItemView.VH>() {

    override fun onCreateViewHolder(parent: ViewGroup): VH {
        val itemView = LayoutInflater.from(parent.context)
            .inflate(R.layout.custom_item_view, parent, false)
        return VH(itemView)
    }

    override fun onBindViewHolder(holder: VH, path: String, addImageView: AddImageView) {
		//...
    }

    class VH(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val ivCover: ImageView = itemView.findViewById(R.id.ivCover)
    }
}

可用的属性和方法

/** 是否开启震动 */
var enableVibrate: Boolean = true

/** 震动时长 */
var vibrateDuration: Long = 100L

/** 动画的相关配置 */
var enableAnimation: Boolean = true
var animDuration: Long = 100
var scaleValue: Float = 1.1f

/** 总共的itemCount */
var maxCount = Int.MAX_VALUE

/** 一排的itemCount */
var spanCount = 3

/** item之间的间距 */
var itemGap: Int = 0

/** 是否开启拖拽排序 */
var enableDrag: Boolean = true

/** 点击事件 */
var onItemViewClickListener: ((position: Int, path: String) -> Unit)? = null
var onAddViewClickListener: ((position: Int) -> Unit)? = null

/** 更新数据源的一系列方法 */
fun setItems(paths: List<String>)
fun addItem(path: String)
fun addItem(paths: List<String>)
fun removeItem(path: String)
fun removeItem(position: Int)
fun getItems()

版本迭代

About

🔥🔥🔥 - 选择照片的自定义九宫格View,扩展性极高。

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.