我的项目无法在预览中呈现布局.我的Android Studio版本3.1.2.我正在使用API 28.这是我的activity_main.xml
<?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=".MainActivity"
android:id="@+id/frame_container">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello World"
android:gravity="center"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
这很简单,只是将Hello World打印到布局,但它无法显示.错误如下:

我搜索解决问题,解决方案是使用API 26.我尝试,一切正常,预览成功.但是我创建片段活动,问题又回来了,预览无法显示. 如果您有新的解决方案,请帮助我!
小智 5
我最近遇到了同样的问题,尽管它是一个精灵简单的项目.
我尝试了23级(Mashmallow)没有任何变化.我卸载了Android Studio,重新安装它,它没有做任何更改,错误仍然存在...
然后我意识到这个问题来自一个依赖(最近可能是谷歌更新了一个错误).解决方案是使用以前的版本.
转到文件 - >项目结构 - >模块应用程序 - >依赖项选项卡.项目创建期间向导使用的默认值为com.android.support:appcompat-v7:28.0.0-alpha3
简单修改到com.android.support:appcompat- V7:27.1.1
在app\res\values\styles.xml中更改
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
Run Code Online (Sandbox Code Playgroud)
至
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
Run Code Online (Sandbox Code Playgroud)
(在Android Studio 3.0布局编辑器中渲染错误)
| 归档时间: |
|
| 查看次数: |
3475 次 |
| 最近记录: |