美文网首页
kotlin实现弹出Window在屏幕最低端

kotlin实现弹出Window在屏幕最低端

作者: Lost_Robot | 来源:发表于2017-07-06 15:32 被阅读27次

    需求:需要在任意页面的最低端,弹出一个Window

    编写一个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   //点击外部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);
        }
    
    }
    

    调用该类:

           //初始化,上传本地视频和照片页面
            val layoutInflater = activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
            // 获取屏幕宽高
            val weight = resources.displayMetrics.widthPixels
            val height = resources.displayMetrics.heightPixels
           //初始化该对象
            mPopWindow = PopLoadingWindow(layoutInflater, weight, height)
            mPopWindow!!.mUpLoading_btn_cancel!!.setOnClickListener(this)
            mPopWindow!!.mUpLoading_btn_local!!.setOnClickListener(this)
            mPopWindow!!.mUpLoading_btn_new!!.setOnClickListener(this)
    

    相关文章

      网友评论

          本文标题:kotlin实现弹出Window在屏幕最低端

          本文链接:https://www.haomeiwen.com/subject/mrihhxtx.html