kotlin實(shí)現(xiàn)彈出Window在屏幕最低端

需求:需要在任意頁(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)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫(kù)、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,269評(píng)論 4 61
  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,023評(píng)論 25 709
  • 茶為萬(wàn)病之藥,有很好的保健功能。 有人認(rèn)為,小孩不能喝茶,那一般指的是綠茶等對(duì)胃有一定刺激的茶。黑茶,其實(shí)不需要喝...
    尚花珍閱讀 185評(píng)論 0 0
  • 從實(shí)驗(yàn)室Love Building出門向西,正對(duì)面是田徑場(chǎng)。無(wú)論下雨或是晴天,田徑場(chǎng)上空開(kāi)闊,總是一副舒心場(chǎng)景。跑...
    只如故人閱讀 301評(píng)論 0 0
  • 現(xiàn)在的人隨著生活水平的提高,每天攝入的多,消耗的少,多余的能量自然就會(huì)轉(zhuǎn)化為脂肪儲(chǔ)存起來(lái)了!再加上每個(gè)人的基礎(chǔ)代謝...
    丹丹_4041閱讀 301評(píng)論 0 1

友情鏈接更多精彩內(nèi)容