У меня есть плавающая кнопка, когда я нажимаю на нее, появляется собственный макет. Проблема в том, что отображение занимает слишком много времени, иногда до 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 секунд).
Я бы хотел, чтобы диалоговое окно появлялось на экране максимум через 1 секунду
Подробнее здесь: https://stackoverflow.com/questions/783 ... ng-on-scre
Мобильная версия