简体   繁体   中英

My (Specific) layout causes Android Studio XML Layout Preview to keep on loading and not displaying the preview

I am making a layout which contains CardView and nested Linear Layouts. When I made the layout for the first time it works fine and the preview window is also displaying the changes. After a day when I open android Studio the preview window keep saying "Waiting for build to finish". So I thought that it is bug related to IDE.

I tried all the solutions that are recommended here:

  • Clean Project
  • Rebuild Invalidate Cache & restart
  • Delete the caches folder from Gradle

But I found out that issue was with my layout beacuse I deleted the layout rebuild the project and preview works fine again. Now I tried to make the same layout again from start but it still happens again. It is very strange for me as my layout is simple, I have created Similar layouts before with no issue whatsoever. I am using the Latest Api Version 29, with latest build tools and latest Android Studio.

Here is my layout code:

<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>

The cause of the issue is Slider. I'm trying to solve it too but still unsuccessful.

Sorry for late reply... Use AppCompatSlider or simply replace it by the traditional Seekbar . I also faced the same issue with material slider.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM