Android 맞춤형 PopWindow
10264 단어 세부 기능의 실현
위 코드:
class PlayListPopWindow(context: Context, adapter: PopWindowAdapter,listener:BaseQuickAdapter.OnItemClickListener,val window: Window):PopupWindow() {
var alpha:Float = 0f
init {
//
alpha = window.attributes.alpha
//
val view = LayoutInflater.from(context).inflate(R.layout.pop_playlist,null,false)
// recyclerview
val recyclerview = view.findViewById<RecyclerView>(R.id.pop_recy)
//
recyclerview.layoutManager = LinearLayoutManager(context)
recyclerview.adapter= adapter
adapter.setOnItemClickListener(listener)
contentView = view
//
width = ViewGroup.LayoutParams.MATCH_PARENT
// 3/5
val manager =context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val point = Point()
manager.defaultDisplay.getSize(point)
val windowheight = point.y
height = (windowheight*3)/5
//
isFocusable = true
//
isOutsideTouchable = true
// dismiss
setBackgroundDrawable(ColorDrawable())
// popwindow
animationStyle = R.style.pop
}
override fun showAsDropDown(anchor: View?, xoff: Int, yoff: Int, gravity: Int) {
super.showAsDropDown(anchor, xoff, yoff, gravity)
// popwindow
val attarbutes = window.attributes
attarbutes.alpha = 0.3f
//
window.attributes = attarbutes
}
override fun dismiss() {
super.dismiss()
//
val attarbutes = window.attributes
attarbutes.alpha = alpha
window.attributes = attarbutes
}
}
실현 클래스
//
override fun onItemClick(adapter: BaseQuickAdapter<*, *>?, view: View?, position: Int) {
//
Iservice?.playPosition(position)
}
//
list?.let {
val adapter = PopWindowAdapter(it)
//
val bottomH = woshibottom.height
val popWindow = PlayListPopWindow(this,adapter,this,window)
popWindow.showAsDropDown(woshibottom,0,bottomH)
}