V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
doublemark
V2EX  ›  Android

android studio 无法预览 Layout 布局

  •  
  •   doublemark · 2019-02-26 11:31:02 +08:00 · 5581 次点击
    这是一个创建于 1857 天前的主题,其中的信息可能已经有所发展或是发生改变。

    没法贴图,之前还是没问题的,现在打开 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 有遇到过这个问题的吗,求助。

    5 条回复    2019-02-27 00:15:25 +08:00
    xbigfat
        1
    xbigfat  
       2019-02-26 11:44:34 +08:00
    无法预览是因为 Gradle 没有 Fully Sync 所以资源有错误。
    高阶 compileSdkVersion 降级到低阶会出现资源错误,特别是 Theme 之类的 Resource 文件错误
    建议就用 28 降下来要删除很多东西的和依赖
    xbigfat
        2
    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
        3
    zoeyzhang  
       2019-02-26 15:00:25 +08:00
    预览不了的话 可以先看下 design 页的 issues 会有 warning 和 error 提示 可能是高版本 theme 不兼容的问题
    diy886
        4
    diy886  
       2019-02-26 16:37:06 +08:00
    项目能运行吗,不能的话先调通
    试试预览界面改 theme 和 invalidate cache/restart
    huruwo
        5
    huruwo  
       2019-02-27 00:15:25 +08:00
    theme 继承 base 试试 我就是预览不了说主题样式问题 改成 base 就行
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1712 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:42 · PVG 00:42 · LAX 09:42 · JFK 12:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.