Android Studio 3.1 layout preview does not show preview for some layouts

前端 未结 4 588
情深已故
情深已故 2020-12-20 14:30

Since today morning I started encountering this weird issue. Android Studio layout preview panel and Design view was not displaying some of my layouts which were perfectly f

相关标签:
4条回答
  • 2020-12-20 14:48

    My trouble was in NDK - just update it and clean + rebuild project.

    0 讨论(0)
  • 2020-12-20 14:49

    For Android Studio 3.1 Gradle version, with plugin version 28.0.0, add implementation 'com.android.support:appcompat-v7:28.0.0-alpha1' instead of implementation 'com.android.support:appcompat-v7:28.0.0-rc01'.

    0 讨论(0)
  • 2020-12-20 15:02

    After many failed attempts and submitting it to Android Studio bug tracker and giving it an another try. I found that it was due to a missing "+".

    Sample layout to demonstrate the issue

    <?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:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TextView
            android:id="@+id/rightTextView"
            style="@style/Base.TextAppearance.AppCompat.Medium"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="24dp"
            android:padding="12dp"
            android:text="This is a sample TextView at Right"
            app:layout_constraintStart_toEndOf="@+id/leftTextView" />
    
        <TextView
            android:id="@id/leftTextView"
            style="@style/Base.TextAppearance.AppCompat.Large"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="12dp"
            android:text="Left"
            android:textColor="@color/colorAccent" />
    
    </android.support.constraint.ConstraintLayout>
    

    The issue was because of a missing + in leftTextView id declaration. After changing the line (line no. 18)

    android:id="@id/leftTextView"

    to

    android:id="@+id/leftTextView"

    Android Studio layout preview panel started displaying the layout.

    Note : I always used to declare view ids (i.e., "@+id") only once in a layout file at its first occurrence(either declaration or reference) and there was no issue with layout preview or running the App till now

    0 讨论(0)
  • In my case, I did build and then clicked Force Refresh Layout started showing preview

    Try whether this solves your issue,

    0 讨论(0)
提交回复
热议问题