Android 맞춤형 PopWindow

내가 실현한 효과는 단추를 누르면 밑에 popwindow가 나오는 애니메이션 창의 색이 회색으로 바뀌어recyclerview 목록을 표시하고, 클래스 전송 어댑터 데이터와 클릭 이벤트를 실현하며, 외부에 popwindow를 숨기는 것을 실현하는 것이다
위 코드:
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)
        }

좋은 웹페이지 즐겨찾기