Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DialogFragment 中通过继承 BasePopup 的方式使用未能显示,在 activity 中使用可以显示 #145

Closed
yifpro opened this issue Jan 28, 2019 · 5 comments

Comments

@yifpro
Copy link

yifpro commented Jan 28, 2019

  • 系统版本:7.0
  • 库版本:2.1.7
  • 问题描述/重现步骤:DialogFragment 中通过继承 BasePopup 的方式使用未能显示,在 activity 中使用可以显示
  • 问题代码/截图:
    `class SalesUnitPopup(context: Context) : BasePopupWindow(context, true) {

private val mList = arrayListOf()
private val mAdapter by lazy { SalesUnitAdapter(R.layout.item_popup_window, mList) }
private var mOnItemClickListener: ((String) -> Unit)? = null

override fun onCreateContentView(): View {
val view = createPopupById(R.layout.view_popup_content)
val recyclerView = view.findViewById(R.id.recyclerView)
recyclerView.setBackgroundResource(R.drawable.bg_popup_down)
mAdapter.setOnItemClickListener { _, _, position ->
mOnItemClickListener?.invoke(mList[position])
}
recyclerView.run {
layoutManager = LinearLayoutManager(context)
adapter = mAdapter
}
return view
}

fun setOnItemClickListener(listener: (String) -> Unit) {
mOnItemClickListener = listener
}

fun setData(data: List) {
mList.clear()
mList.addAll(data)
mAdapter.notifyDataSetChanged()
}

init {
delayInit()
}
}

SalesUnitPopup(activity).setPopupGravity(Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL).showPopupWindow(tv)
`

  • 报错信息:

@razerdp
Copy link
Owner

razerdp commented Jan 29, 2019

我这里留意到你用了延迟加载,不过应该没关系- -请问你的popup是在哪里调用的呢

@yifpro
Copy link
Author

yifpro commented Jan 29, 2019

我这里留意到你用了延迟加载,不过应该没关系- -请问你的popup是在哪里调用的呢

抱歉,我未对位于 dialogFragment 之上的 popup 不能正常显示,做尽可能的测试,后经测试发现,popup 是显示的,但显示位于 activity 之上,dialogFragment 之下,以下是我进行测试的代码
`class CustomDialog : DialogFragment() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    //setStyle(DialogFragment.STYLE_NORMAL, R.style.BottomDialog)
}

/*override fun onStart() {
    super.onStart()
    dialog?.window?.setLayout(dp2px(360f), dp2px(500f))
    getDialog().getWindow().setBackgroundDrawable(null)
}*/

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    /*getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
    val window = getDialog().getWindow();
    val lp = window.getAttributes();
    lp.gravity = Gravity.BOTTOM; //底部
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    window.setAttributes(lp);*/

    val view = View.inflate(activity, R.layout.fragment_dialog, null)
    val tv = view.findViewById<TextView>(R.id.tvPopup)
    tv.setOnClickListener {
        SalesUnitPopup(activity!!).setBackgroundColor(0).setPopupGravity(Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL).showPopupWindow(tv)
    }
    return view
}

//******** dp to px ********
fun dp2px(dpValue: Float): Int {
    return dp2px(activity, dpValue)
}

}`

@razerdp
Copy link
Owner

razerdp commented Jan 30, 2019

我待会写个demo测试一下

@razerdp
Copy link
Owner

razerdp commented Feb 18, 2019

@Yifpro96 经检查,发现popup确实是在dialogfragment之下显示,关于这方面的问题,我跟踪一下哈

@razerdp
Copy link
Owner

razerdp commented Feb 18, 2019

【Candy】2.1.9-alpha已修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants