Раздутый пользовательский макет диалогового окна занимает 2–3 секунды, прежде чем появится на экранеAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Раздутый пользовательский макет диалогового окна занимает 2–3 секунды, прежде чем появится на экране

Сообщение Anonymous »

У меня есть ViewPager2 с несколькими фрагментами. в одном из фрагментов я реализовал собственный макет для диалогового окна.
У меня есть плавающая кнопка, когда я нажимаю на нее, появляется собственный макет. Проблема в том, что отображение занимает слишком много времени, иногда до 3 секунд.
вот код пользовательского макета: вот как раздувается код (мы находимся во фрагменте):

Код: Выделить всё

@SuppressLint("InflateParams")
private fun setupUI() {
// inflate the 'Add Item' custom view for the dialog
val customItemView = layoutInflater.inflate(R.layout.groceries_edit_layout, null)
itemLayoutBinding = GroceriesEditLayoutBinding.bind(customItemView.rootView)

binding.groceriesFloatingButton.setOnClickListener {
setupEditDialog()
itemLayoutBinding.removeButton.visibility = View.GONE
itemLayoutBinding.textViewGroceryTitle.text = getString(R.string.groceries_add_new_item)
itemLayoutBinding.itemEditText.setText("")
itemLayoutBinding.priceEditText.setText("")
itemLayoutBinding.groceriesTypeSpinner.setSelection(0)
itemLayoutBinding.quantityEditText.setText("1")
dialog.create()
dialog.show()
}

//custom layout buttons
itemLayoutBinding.saveButton.setOnClickListener {
saveItem()
showGroceryList()
}

itemLayoutBinding.removeButton.setOnClickListener {
removeItem()
showGroceryList()
}

// spinner adapter
spinnerAdapter = SpinnerAdapter(requireContext(), SpinnerCategories.Categories.list!!) // !! guarantees list won't be null
itemLayoutBinding.groceriesTypeSpinner.adapter = spinnerAdapter
}
при нажатии плавающей кнопки!:

Код: Выделить всё

private fun setupEditDialog() {
// detach layout if already attached to a parent
if(itemLayoutBinding.root.parent != null) {
val parentView = itemLayoutBinding.root.parent as ViewGroup
parentView.removeView(itemLayoutBinding.root)
}

// androidx.appcompat.R.style.Base_Theme_AppCompat_Light_Dialog_MinWidth
// com.google.android.material.R.style.MaterialAlertDialog_MaterialComponents_Body_Text
dialog = Dialog(requireContext(), androidx.appcompat.R.style.Base_Theme_AppCompat_Light_Dialog_MinWidth)

// we have a title in the custom layout
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialog.setCancelable(true)
dialog.setContentView(itemLayoutBinding.root)
// when item is clicked on but user tap somewhere else on the screen dismissing the dialog
dialog.setOnCancelListener {
dialog.hide()
recyclerSectionList = null
recyclerItemPosition = null
}

}
Я попробовал AlertDialog и AlertFragment, но оба они появляются на экране примерно в одно и то же время (занимает 2–3 секунды)
Я пробовал с AlertDialog, и я попробовал AlertFragment, но оба появляются на экране примерно в одно и то же время (занимает от 2 до 3 секунд).
Я бы хотел, чтобы диалоговое окно появлялось на экране максимум через 1 секунду

Подробнее здесь: https://stackoverflow.com/questions/783 ... ng-on-scre
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»