Android积木之PopupWindow



class DropListPopWin(var context: Context) : PopupWindow() {

    var layoutInflater: LayoutInflater
    lateinit var target: View
    var mData: List? = null

    init {
        layoutInflater = LayoutInflater.from(context)
        isFocusable = true
        isTouchable = true
        isOutsideTouchable = true

    }

    constructor(context: Context, view: View,mData:List) : this(context) {
        target=view
        this.mData=mData
        initView(context)
    }

    fun initView(context: Context) {
        this.target = target
        width = target.measuredWidth
        height = ViewGroup.LayoutParams.WRAP_CONTENT
        setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        contentView = layoutInflater.inflate(R.layout.home_pop_list, null)
        var listView = contentView.findViewById(R.id.list)
        listView.layoutManager=LinearLayoutManager(context)
        listView.adapter = ListViewAdapter(mData!!, context)
        super.setContentView(contentView)
    }

    fun show() {
        var targetHeight = target.height

        showAsDropDown(target!!, 0, -targetHeight / 2)
    }
}

 

你可能感兴趣的:(Android积木)