Раздувание ConstraintLayout падает на некоторых устройствах - PullRequest
0 голосов
/ 10 мая 2018

У меня есть xml-макет, который работает на некоторых устройствах, но вылетает, когда надувается на других (xml-код показан только частично):

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraintLayout_record_audio"
android:minWidth="@android:dimen/dialog_min_width_major"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>

Раздувание макета отлично работает на некоторых устройствах, но вызывает InflateException на других.

Я нашел виновника в своем xml-файле:

<!-- Causes InflateException on some devices: 
     android:minWidth="@android:dimen/dialog_min_width_major"  -->

К сожалению, после удаления строки, вызывающей InflateException, android:layout_height="wrap_content" больше не работает. layout_height всегда отображается так, как если бы он был установлен на "match_parent". Есть идеи о том, что происходит и как это решить?

ДОБАВЛЕНО ДЛЯ ЯСНОСТИ

Вот как я называю Диалог:

fun showRecordAudioDialog(view: View, categoryId: String, detailId: String) {
    val dialog = RecordAudioDialogFragment.newInstance(categoryId, detailId)
    dialog.show(this@DetailsActivity.supportFragmentManager, "RecordAudioDialog")
}

В моем RecordAudioDialogFragment:

    // Use the Builder class for convenient dialog construction
    val builder = AlertDialog.Builder(activity, style.CustomTheme_Dialog)

    val inflater = activity.layoutInflater
    val rootView = inflater.inflate(layout.dialog_record_audio, null)

1 Ответ

0 голосов
/ 13 мая 2018

По какой-то странной причине android:layout_height не работает, если android:minWidth не установлено.

Итак, в dimens.xml нам нужно добавить строку вроде <dimen name="dialog_min_with">500dp</dimen>

и затем добавьте android:minWidth="@dimen/dialog_min_with" в наш mylayout.xml файл.

Вот так теперь выглядит заголовок файла layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/constraintLayout_record_audio"
android:minWidth="@dimen/dialog_min_with"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
...