需求:需要在任意頁(yè)面的最低端,彈出一個(gè)Window
編寫一個(gè)Window類:
class PopLoadingWindow(layoutInflater: LayoutInflater, weight: Int, height: Int) {
var mPopWindow: PopupWindow? = null
var mView: View? = null
val mTake_New_id: Int = R.id.mine_uploading_btn_new
val mTake_local_id: Int = R.id.mine_uploading_btn_local
val mCancel_id: Int = R.id.mine_uploading_btn_cancel
var mUpLoading_btn_new: Button? = null
var mUpLoading_btn_local: Button? = null
var mUpLoading_btn_cancel: Button? = null
init {
initView(layoutInflater, weight, height)
}
fun initView(layoutInflater: LayoutInflater, w: Int, h: Int) {
mView = layoutInflater.inflate(R.layout.popue_uploading_window, null)
mUpLoading_btn_new = mView!!.findViewById(R.id.mine_uploading_btn_new) as Button
mUpLoading_btn_local = mView!!.findViewById(R.id.mine_uploading_btn_local) as Button
mUpLoading_btn_cancel = mView!!.findViewById(R.id.mine_uploading_btn_cancel) as Button
//獲取屏幕寬高
val weight = w
val height = h * 2 / 5
mPopWindow = PopupWindow(mView, weight, height);
mPopWindow!!.isFocusable = true
mPopWindow!!.isOutsideTouchable = true //點(diǎn)擊外部popueWindow消失
mPopWindow!!.animationStyle = R.style.Anim_style
}
fun dismiss() {
mPopWindow!!.dismiss()
}
fun show() {
//確定Window顯示的位置,bottom和x=0,y=0這樣的位置
mPopWindow!!.showAtLocation(mView, Gravity.BOTTOM, 0, 0);
}
}
調(diào)用該類:
//初始化,上傳本地視頻和照片頁(yè)面
val layoutInflater = activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
// 獲取屏幕寬高
val weight = resources.displayMetrics.widthPixels
val height = resources.displayMetrics.heightPixels
//初始化該對(duì)象
mPopWindow = PopLoadingWindow(layoutInflater, weight, height)
mPopWindow!!.mUpLoading_btn_cancel!!.setOnClickListener(this)
mPopWindow!!.mUpLoading_btn_local!!.setOnClickListener(this)
mPopWindow!!.mUpLoading_btn_new!!.setOnClickListener(this)