DylanCaiCoding / ViewBindingKTX

The most comprehensive utils of ViewBinding. (最全面的 ViewBinding 工具,支持 Kotlin 和 Java 用法,支持 BRVAH,支持封装到基类,支持 DataBinding,支持选择是否使用反射)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

popupwindow怎么使用?

wealive opened this issue · comments

目前没有对 PopupWindow 进行封装,可以考虑封装一下。你先用回 ViewBinding 原本的用法:

val popupItemBinding = PopupItemBinding.inflate(layoutInflater)
val popupWindow = PopupWindow(
   popupItemBinding.root, 
   ViewGroup.LayoutParams.MATCH_PARENT,
   ViewGroup.LayoutParams.WRAP_CONTENT
)

在最新的 2.0.0 版本增加了快速创建 PopupWindow 的方法,默认的宽高是 WRAP_CONTENT,可以传参修改宽高为 MATCH_PARENT 或者自定义大小。

private val popupWindow by popupWindow<LayoutPopupBinding> {
// private val popupWindow by popupWindow(LayoutPopupBinding::inflate) {
  btnLike.setOnClickListener { 
    // ... 
  }
}