从今天早上开始,我开始遇到这个奇怪的问题。Android Studio布局预览面板和设计视图没有显示我的一些布局,直到我将Android Studio从3.0.1更新到3.1。
我尝试了以下没有帮助:
Android Studio详细信息:
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
在我的例子中,我确实构建了,然后单击强制刷新布局开始显示预览
试试这是否解决了你的问题,
经过多次失败的尝试并将其提交给Android Studiobug跟踪器并再试一次。我发现这是由于缺少“”。
演示问题的示例布局
<?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>
问题是因为leftTextView id声明中缺少。更改行后(第18行)
android: id="@id/左侧文本视图"
到
Android:id="@id/leftTextView"
Android Studio布局预览面板开始显示布局。
注意:我总是在布局文件第一次出现时只声明一次视图id(即“@id”)(声明或引用),到目前为止布局预览或运行应用程序都没有问题
对于Android Studio 3.1 Gradle版本,插件版本为28.0.0,添加实现'com.android.support: appcompat-v7:28.0.0-alpha1'
而不是实现'com.android.support:appcompat-v7:28.0.0-rc01'
。