razerdp / BasePopup

Android下打造通用便捷的PopupWindow弹窗库
https://github.com/razerdp/BasePopup
Apache License 2.0
5.2k stars 759 forks source link

弹窗的宽度在 平行世界中显示 大小仍为全屏,不自动适配分屏时的应用宽度。 #479

Closed pichsy closed 2 years ago

pichsy commented 2 years ago

在pad上 使用分屏,弹窗宽度 不会发生变化,重新弹出来也不变化,一直为屏幕最大宽度。

class SendMessagePopup constructor(var context: Context, inline var onSend: (String) -> Unit) : BasePopupWindow(context) {

private lateinit var binding: TestPopupSendMessageBinding

init {
    setContentView(R.layout.test_popup_send_message)
}

override fun onViewCreated(contentView: View) {
    super.onViewCreated(contentView)
    setOutSideDismiss(true)
    isOutSideTouchable = true
    popupGravity = Gravity.BOTTOM
    setKeyboardAdaptive(true)
    hideKeyboardOnDismiss(true)
    binding = TestPopupSendMessageBinding.bind(contentView)
    binding.btnSend.setOnClickListener {

        if (!TextUtils.isEmpty(binding.etMessage.text?.trim())) {
            KeyBoardUtils.hideKeyboard(binding.etMessage)
            onSend(binding.etMessage.text.toString())
            dismiss()
            binding.etMessage.setText("")
        }
    }

    binding.etMessage.setOnEditorActionListener { v, actionId, event ->
        if (actionId == EditorInfo.IME_ACTION_SEND) {
            if (!TextUtils.isEmpty(binding.etMessage.text?.trim())) {
                KeyBoardUtils.hideKeyboard(binding.etMessage)
                onSend(binding.etMessage.text.toString())
                dismiss()
                binding.etMessage.setText("")
            }
            return@setOnEditorActionListener true
        }
        return@setOnEditorActionListener false
    }
}

override fun showPopupWindow() {
    super.showPopupWindow()
    setAutoShowKeyboard(binding.etMessage, true)
}

override fun onCreateShowAnimator(): Animator {
    return AnimationHelper.asAnimator()
        .withTranslation(TranslationConfig.FROM_BOTTOM)
        .toShow()
}

override fun onCreateDismissAnimator(): Animator {
    return AnimationHelper.asAnimator()
        .withTranslation(TranslationConfig.TO_BOTTOM)
        .toDismiss()
}

} <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="58dp" android:background="#fff">

<androidx.appcompat.widget.AppCompatEditText
    android:id="@+id/et_message"
    android:layout_width="180dp"
    android:layout_height="match_parent"
    android:layout_marginStart="16dp"
    android:layout_marginEnd="16dp"
    android:textColor="#000"
    android:hint="请输入"
    android:gravity="center_vertical"
    android:textColorHint="#666666"
    android:textSize="15sp"
    android:imeActionLabel="发送"
    android:imeOptions="actionSend"
    android:singleLine="true" />

<com.pichs.common.widget.cardview.XCardButton
    android:id="@+id/btn_send"
    android:layout_width="68dp"
    android:layout_height="44dp"
    android:layout_gravity="center"
    android:layout_marginEnd="16dp"
    android:background="#00f"
    android:gravity="center"
    android:text="发送"
    android:textColor="#fff"
    app:xp_isRadiusAdjustBounds="true" />

razerdp commented 2 years ago

目前仍未去适配分屏哦~