安卓开发工具Android Studio 3中,约束布局编辑器无法正常工作

13

我最近安装了Android Studio 3,但约束布局显示为灰色窗口。我尝试了各种方法,但是无法解决这个问题。

提前感谢任何提供帮助的人:

输入图像描述

输入图像描述

XML代码:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
    xmlns:android="schemas.android.com/apk/res/android"; 
    xmlns:app="schemas.android.com/apk/res-auto"; 
    xmlns:tools="schemas.android.com/tools"; 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.chihaoui.myapplication.MainActivi‌​ty"> 
</android.support.constraint.ConstraintLayout>

展示给我们 XML 代码。 - Pulak
<?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" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.chihaoui.myapplication.MainActivity"></android.support.constraint.ConstraintLayout> - max taylor
你试过运行这个应用程序吗?它正在运行吗? - Pulak
"没有起作用" - 为什么呢?尝试使用模拟器。我怀疑如果没有错误并且应用程序运行良好,则问题与设计编辑器有关。 - Pulak
@maxtaylor,请发布您的logcat。 - crgarridos
显示剩余2条评论
4个回答

17

我只是帮助完成了这个项目并赚到了报酬

示例


3
很奇怪,但是通过点击Build -> Make project可以使布局编辑器正常工作。 - netcyrax

2

在 build.gradle 文件中,只需进行以下更改:

androidx.constraintlayout:constraintlayout:2.1.3

to

androidx.constraintlayout:constraintlayout:2.0.4

这对我有用,似乎2.1.3版本与编译的31 SDK不兼容。 - user3340335

2
我遇到了类似的问题。我的问题通过在app/build.gradle中添加以下几行代码得到解决:
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation('com.android.support:appcompat-v7:28.0.0') {
    force = true
}

请注意force = true部分。最初的回答。

1
你可以使用 AndroidX 支持库来替代 v7 。来源:https://developer.android.com/topic/libraries/support-library/packages#v7 - MD Naseem Ashraf

0
你同步了项目吗?如果你没有同步项目,gradle文件中会出现黄色的消息,这样它就无法工作。

你能把设计编辑器的API版本降低并告诉我这是否解决了问题吗? - thisactuallyworks
有趣的是,没有错误,但当我运行应用程序时,弹出窗口会出现“很遗憾,我的应用程序已停止” - max taylor

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接