android studio 无法预览 Layout 布局

2019-02-26 11:31:02 +08:00
 doublemark

没法贴图,之前还是没问题的,现在打开 Design 标签,预览图是空白,中间显示 android...DrawerLayout Build.gradle 如下: apply plugin: 'com.android.application'

android { compileSdkVersion 28 defaultConfig { applicationId "com.example.nettywificomp" minSdkVersion 21 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release } } buildToolsVersion '28.0.3' }

dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support:design:28.0.0' implementation 'de.hdodenhof:circleimageview:2.1.0' implementation 'javolution:javolution:5.3.1' implementation 'com.contrarywind:Android-PickerView:4.1.7' implementation 'com.github.huangyanbin:SmartTable:2.2.0' implementation 'com.github.GrenderG:Toasty:1.4.0' implementation 'com.nbsp:library:1.8' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' }

看 StackOverflow 提示说降到 27,但是降到 27 还是一堆 Error 有遇到过这个问题的吗,求助。

6218 次点击
所在节点    Android
5 条回复
xbigfat
2019-02-26 11:44:34 +08:00
无法预览是因为 Gradle 没有 Fully Sync 所以资源有错误。
高阶 compileSdkVersion 降级到低阶会出现资源错误,特别是 Theme 之类的 Resource 文件错误
建议就用 28 降下来要删除很多东西的和依赖
xbigfat
2019-02-26 11:48:48 +08:00
还有就是代码贴的规范一点,帮你尝试格式化了不知道会不会成功。。。
```
android {
compileSdkVersion 28 defaultConfig {
applicationId "com.example.nettywificomp" minSdkVersion 21 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} buildTypes {
release {
minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release
}
} buildToolsVersion '28.0.3'
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'de.hdodenhof:circleimageview:2.1.0'
implementation 'javolution:javolution:5.3.1'
implementation 'com.contrarywind:Android-PickerView:4.1.7'
implementation 'com.github.huangyanbin:SmartTable:2.2.0'
implementation 'com.github.GrenderG:Toasty:1.4.0'
implementation 'com.nbsp:library:1.8'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
```
zoeyzhang
2019-02-26 15:00:25 +08:00
预览不了的话 可以先看下 design 页的 issues 会有 warning 和 error 提示 可能是高版本 theme 不兼容的问题
diy886
2019-02-26 16:37:06 +08:00
项目能运行吗,不能的话先调通
试试预览界面改 theme 和 invalidate cache/restart
huruwo
2019-02-27 00:15:25 +08:00
theme 继承 base 试试 我就是预览不了说主题样式问题 改成 base 就行

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/538797

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX