效果图:
image.png
popupwindow布局:
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/tran_50"
android:orientation="vertical">
android:layout_width="match_parent"
android:layout_height="@dimen/dp_1"
android:background="@color/hui_d8" />
android:id="@+id/rvList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:overScrollMode="never" />
android:layout_width="match_parent"
android:layout_height="@dimen/dp_10"
android:background="@drawable/white_bottom_cricle_shape" />
android:id="@+id/emptyView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
white_bottom_cricle_shape
android:shape="rectangle">
popupwindow
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
class StorePopupwindow(var context: Context, var listener:onAdapterAnyListener) : PopupWindow(),onAdapterAnyListener {
var rvList:RecyclerView? = null
var applyAdapter:StoreListAdapter? = null
var emptyView:View? = null
override fun onAdapterViewClick(postion: Int, data1: Any?, data2: Any?, data3: Any?) {
listener?.onAdapterViewClick(postion,data1,data2,data3)
this.dismiss()
}
init {
width = ViewGroup.LayoutParams.MATCH_PARENT
height = ViewGroup.LayoutParams.WRAP_CONTENT
isOutsideTouchable = true
val view = LayoutInflater.from(context).inflate(R.layout.popupwind_store_view,null,false)
rvList = view.findViewById(R.id.rvList)
emptyView = view.findViewById(R.id.emptyView)
contentView = view
applyAdapter = StoreListAdapter(context)
applyAdapter?.setAdapterClickListener(this)
val lm = LinearLayoutManager(context)
lm.orientation = LinearLayoutManager.VERTICAL
rvList?.let {
with(it){
layoutManager = lm
addItemDecoration(DividerItemDecoration(this.context, DividerItemDecoration.VERTICAL))
adapter = applyAdapter
}
}
emptyView?.setOnClickListener { this.dismiss() }
}
}
显示在某个view下面
val popupWindow = StorePopupwindow(this,this)
popupWindow.showAsDropDown(rlStoreLay,0,0)