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

需求:需要在任意页面的最低端,弹出一个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)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,300评论 4 61
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,638评论 25 709
  • 茶为万病之药,有很好的保健功能。 有人认为,小孩不能喝茶,那一般指的是绿茶等对胃有一定刺激的茶。黑茶,其实不需要喝...
    尚花珍阅读 156评论 0 0
  • 从实验室Love Building出门向西,正对面是田径场。无论下雨或是晴天,田径场上空开阔,总是一副舒心场景。跑...
    只如故人阅读 268评论 0 0
  • 现在的人随着生活水平的提高,每天摄入的多,消耗的少,多余的能量自然就会转化为脂肪储存起来了!再加上每个人的基础代谢...
    丹丹_4041阅读 274评论 0 1