简体   繁体   中英

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

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 fine until I updated Android Studio from 3.0.1 to 3.1 .

I tried following which didn't helped :

  1. Updated buildTools from 27.0.2 to 27.0.3
  2. Updated support library from 27.0.2 to 27.1.1
  3. Updated constraint layout library from 1.1.0-beta5 to 1.1.0-beta6
  4. Synced Project with Gradle files multiple times
  5. Clean and Rebuilt project multiple times
  6. Invalidated and Restarted Android Studio
  7. Closed project from File menu and reopened it (I suspected it was due to some mismanagement of layout preview cache which was not getting cleared)
  8. Finally restarted my PC

Android Studio details :

Android Studio 3.1
Build #AI-173.4670197, built on March 22, 2018
JRE: 1.8.0_152-release-1024-b02 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 8.1 6.3

In my case, I did build and then clicked Force Refresh Layout started showing preview

Try whether this solves your issue,

在此处输入图片说明

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 (ie, " @+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

对于 Android Studio 3.1 Gradle 版本,插件版本为 28.0.0,添加implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'而不是implementation 'com.android.support:appcompat-v7:28.0.0-rc01'

我的问题是在 NDK - 只需更新它并清理 + 重建项目。

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