您的位置:首页 > 移动开发 > Android开发

android 7.0 PopWinow BUG

2018-01-16 09:30 274 查看
1.showAsDropDown()的全屏BUG

mPopupWindow = PopupWindow(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)
.apply {
val inflate = View.inflate(context, R.layout.layout_around_pop, null)
inflate.onClick { dismiss() }
val recyclerView = inflate.find<RecyclerView>(R.id.mRecyclerView)
recyclerView.layoutManager = GridLayoutManager(activity, 5, GridLayoutManager.VERTICAL, false)
value= object : BaseRLAdapter<Clazz>(recyclerView, datas, R.layout.item_popwin_list) {
override fun loadMore() {
//这个方法不会走
}

override fun onConvert(holder: MyHolder?, list: List<Clazz>, position: Int) {

}
}
recyclerView.adapter = value
isOutsideTouchable = false
isFocusable = true
contentView = inflate

}
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.M) {
val location = IntArray(2)
around_type_line.getLocationOnScreen(location)
val y = location[1]
mPopupWindow?.showAtLocation(around_type_line, Gravity.NO_GRAVITY, 0, y + QMUIDisplayHelper.dp2px(activity, 1))
} else {
mPopupWindow?.showAsDropDown(around_type_line)
}

在showAsDropDown之前  进行了一次判断  复制即可 但不知道为什么 任然偶现全屏的BUG

2.PopWindow在activity的onCreate中show的BUG(BadTokenException)

尝试1:onPostCreat OnCreate OnResume onWindowFocusChange

override fun onWindowFocusChanged(hasFocus: Boolean) {
    super.onWindowFocusChanged(hasFocus)
    if (hasFocus && !isFirst) {
        isFirst = true
        initData()
    }
}

尝试2:配合Handler.postDelay()

除了 onWindowFocusChange 或者 配合Handler.postDelay() 能够不报错 其他统一报错(大概意思是 window未初始化 就show? 崩!) 但是别以为问题就此完结了。在调试SDK19(4.4.4)时居然死活不弹出来(此处需要Mark一下),这还不要紧 最要命的是splash界面 卡死了···。那怎么办呢?直接放弃PopWindow呗,毕竟项目是有周期的,先完成任务再说,直 View.GONE
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息