效果图:
image.png
popupwindow布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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">
<View
android:layout_width="match_parent"
android:layout_height="@dimen/dp_1"
android:background="@color/hui_d8" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:overScrollMode="never" />
<!-- 自定义shape底部圆角 -->
<View
android:layout_width="match_parent"
android:layout_height="@dimen/dp_10"
android:background="@drawable/white_bottom_cricle_shape" />
<!-- 底部新增一个view做撑满 -->
<View
android:id="@+id/emptyView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
white_bottom_cricle_shape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white"/>
<corners android:bottomLeftRadius="@dimen/dp_10" android:bottomRightRadius="@dimen/dp_10"/>
</shape>
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)
网友评论