Android Studio Design模式下视图无法显示,尝试常规方案未解决
可行解决方案
- 降级核心依赖版本:你使用的Android Studio 3.6.3为较早版本,与你引入的高版本AndroidX依赖不兼容,会导致布局渲染引擎失效。将dependencies中的对应依赖替换为适配3.6.3的版本,同步项目后重试:
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) // 替换为低版本兼容依赖 implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' }
- 清理IDE缓存重启:依次点击顶部菜单栏
File -> Invalidate Caches / Restart,在弹窗中选择Invalidate and Restart,等待IDE重启后重新打开布局文件。 - 切换布局渲染API版本:打开Design模式后,点击界面顶部预览区域的API版本下拉选择框,将默认的API 28切换为API 27或更低版本,触发重新渲染。
- 移除手动指定的buildToolsVersion:删除build.gradle中
buildToolsVersion "28.0.3"这一行配置,让IDE自动匹配对应版本的构建工具,避免工具版本下载不完整导致的渲染异常。 - 检查布局文件属性:确认布局根节点已添加
tools:context属性指向对应Activity,若缺失可手动补充后重试。
内容的提问来源于stack exchange,提问作者user12616222
相关产品推荐
相关产品推荐

