inventoryMovementPopUp

inventoryMovementPopUp

我要做的是显示一个响应式弹出 View 。我现在所拥有的是,弹出 View 会调整原始线性布局的大小,并且在某些设备上显示得非常糟糕。
这就是线性布局xml的样子
layout.xml
当我运行它时,它就是这样显示的
popupView
这是弹出的 View 代码:

private fun setUpModalProduct() {
        inventoryMovementPopUpView = layoutInflater.inflate(R.layout.modal_inventory_movement,
                null) // inflating popup layout
    val width = (resources.displayMetrics.widthPixels * 0.40).toInt() // 0.90 = 90% of width size
    val height = (resources.displayMetrics.heightPixels * 1).toInt() // 0.90 = 90% of hight size

    inventoryMovementPopUp = PopupWindow(inventoryMovementPopUpView,
            width,  //width value
            height,  //height value
            true) // Creation of popup

    inventoryMovementPopUp!!.animationStyle = android.R.style.Animation_Dialog
    inventoryMovementPopUp!!.showAtLocation(inventoryMovementPopUpView, Gravity.CENTER, 0, 0)

    inventoryMovementPopUp!!.isOutsideTouchable = false
    inventoryMovementPopUp!!.isFocusable = false
}
任何帮助或建议都会很棒,谢谢!

最佳答案

尝试

 val width = 600 //LinearLayout.LayoutParams.WRAP_CONTENT
 val height = LinearLayout.LayoutParams.MATCH_PARENT
并在您的布局xml父级上
android:layout_width="wrap_content"
android:layout_height="match_parent">

07-23 22:50