设置`setMaxHeight`后,会导致Popup整体右移
TxcA opened this issue · 2 comments
TxcA commented
- 系统版本(必须)/ System version (required):HarmonyOS2.0 / Android10
- 库版本(必须)/ Library version (required):3.1.8
- 问题代码/截图(可选)/ Problem code or screenshot (optional):
- 报错信息(可选)/ Error reporting information (optional):
(功能性错误)
设置setMaxHeight
后,会导致Popup整体右移
问题描述/重现步骤请写在这里
Please write the description here.
R.layout.popup_test
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:background="@android:color/holo_red_dark">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never" />
</LinearLayout>
TestPopup.kt
class TestPopup(context: Context) : BasePopupWindow(context) {
override fun onViewCreated(contentView: View) {
super.onViewCreated(contentView)
val rvText: RecyclerView = findViewById(R.id.rv_test)
val adapter = TestAdapter(List(100) { "Item: $it" })
rvText.layoutManager = LinearLayoutManager(context)
rvText.adapter = adapter
}
init {
contentView = createPopupById(R.layout.popup_test)
val screenHeight =
(context.getSystemService(Context.WINDOW_SERVICE) as? WindowManager)?.let { wm ->
val point = Point()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
wm.defaultDisplay.getRealSize(point)
} else {
wm.defaultDisplay.getSize(point)
}
point.y
} ?: 1000
// 加上下方`setMaxHeight`后,会导致popup右移(不确定是否是`layout_marginEnd`失效)
// setMaxHeight((screenHeight * 0.8).toInt())
}
private class TestAdapter(private val data: List<String>) :
RecyclerView.Adapter<TestAdapter.TestViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TestViewHolder =
TestViewHolder(
LayoutInflater.from(parent.context)
.inflate(android.R.layout.simple_list_item_1, parent, false)
)
override fun onBindViewHolder(holder: TestViewHolder, position: Int) {
holder.tvText.text = data[position]
}
override fun getItemCount(): Int = data.size
class TestViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val tvText: TextView = itemView.findViewById(android.R.id.text1)
}
}
}
razerdp commented
问题确认,我去查查
razerdp commented
问题查到了,是3.1.8添加了测量子控件导致,实际上测量了父控件即可。
具体问题:PopupDecorViewProxy.measureWrappedDecorView()
该问题已经在快照版本:
3.1.9-SNAPSHOT
修复
请前往验证。