Мой (Specifi c) макет заставляет Android Studio XML Просмотр макета продолжать загружаться и не отображать предварительный просмотр - PullRequest
1 голос
/ 17 января 2020

Я делаю макет, который содержит CardView и вложенные линейные макеты. Когда я сделал макет в первый раз, он работает нормально, и в окне предварительного просмотра также отображаются изменения. После дня, когда я открываю android Studio, в окне предварительного просмотра появляется сообщение «Ожидание сборки до конца sh». Поэтому я подумал, что это ошибка, связанная с IDE.

Я перепробовал все решения, которые рекомендуются здесь:

  • Очистить проект
  • Восстановить недействительный кэш и перезапустить
  • Удалить папку кэшей из Gradle

Но я обнаружил, что проблема связана с моим макетом , поскольку я удалил макет, перестроил проект, и предварительный просмотр снова работает нормально. Теперь я попытался сделать то же самое макет с самого начала, но это все еще повторяется. Это очень странно для меня, так как мой макет прост, я уже создавал подобные макеты без каких-либо проблем. Я использую последнюю версию Api 29 с последними инструментами для сборки и новейшей Android Studio.

Вот мой код компоновки:

<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/light"
    tools:context=".Ui.Setting">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/setting_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/light"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ToolbarTheme"
        app:title="SETTINGS"
        app:titleMarginStart="40dp"
        app:titleTextColor="@color/dark" />

    <com.google.android.material.textview.MaterialTextView
        android:id="@+id/accessibility"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/setting_toolbar"
        android:layout_marginStart="10dp"
        android:padding="10dp"
        android:text="@string/accessibility"
        android:textColor="@color/dark"
        android:textSize="18sp" />

    <androidx.cardview.widget.CardView
        android:id="@+id/accessibility_card"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/accessibility"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="10dp"
        app:cardCornerRadius="8dp"
        app:cardElevation="10dp"
        app:contentPadding="5dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:baselineAligned="false">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:gravity="center_vertical">

                <com.google.android.material.textview.MaterialTextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="10dp"
                    android:layout_weight="1"
                    android:text="@string/grey_scale" />

                <com.google.android.material.switchmaterial.SwitchMaterial
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    app:useMaterialThemeColors="true" />
            </LinearLayout>
            <View
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="@android:color/darker_gray" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:gravity="center_vertical">

            <com.google.android.material.textview.MaterialTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="10dp"
                android:layout_weight="0.5"
                android:text="@string/text_size" />

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1.5"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:weightSum="3">

                <com.google.android.material.textview.MaterialTextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.5"
                    android:gravity="end"
                    android:text="@string/aminus" />

                <com.google.android.material.slider.Slider
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="2" />

                <com.google.android.material.textview.MaterialTextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="10dp"
                    android:layout_weight="0.5"
                    android:gravity="end"
                    android:text="@string/aplus" />

            </LinearLayout>
        </LinearLayout>



    </androidx.cardview.widget.CardView>
    </RelativeLayout>

Ответы [ 2 ]

2 голосов
/ 24 января 2020

Причиной проблемы является ползунок. Я тоже пытаюсь решить, но все еще безуспешно.

0 голосов
/ 06 мая 2020

Извините за поздний ответ ... Используйте AppCompatSlider или просто замените его на традиционный Seekbar. Я также столкнулся с той же проблемой с ползунком материала.

...