Recyclerview 预览显示灰色屏幕,中间有 android.support.v7.widget.RecyclerView

Recyclerview preview showing grey screen with android.support.v7.widget.RecyclerView in center

我正在尝试将 Recyclerview 添加到我的 activity 布局中,但布局预览显示 this。我遍历了所有可能的答案,并尝试做

之类的事情
  1. 将应用主题更改为 holo.light
  2. <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"> 添加到 res>styles.xml
  3. 检查了所有可能的相关问题,例如 and 并在我的代码中进行了相应的更改。

我的build.gradle文件如下:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.1'
    defaultConfig {
        applicationId "com.myapp.test"
        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'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:support-v4:28.0.0-alpha3'
    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'
    implementation 'com.android.support:design:28.0.0-alpha3'
    implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
    implementation 'com.android.volley:volley:1.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'

}

当我在 activity 中尝试使用坐标布局时,也会出现同样的问题。我正在使用 android studio 3.1.3,我的目标设备是 oreo 版本。

我无法弄清楚问题出在哪里。请帮助我。

尝试在 Android Studio 中的 'File' 中执行“无效缓存/重新启动”。

如果这不起作用,请尝试以下操作:

将此添加到您的 build.gradle(项目)文件中:

configurations.all {
    resolutionStrategy {
        force 'com.android.support:recyclerview-v7:28.0.0-alpha3'
    }
}

试试这个 com.android.support:recyclerview-v7:20.0.+
或删除 alpha 并尝试一下

我认为您应该尝试更改您的 sdk 版本并使用旧版本的 recyclerview(可能是版本 27)和您使用过的其他库,看看它是否有效。

试试这个:

compileSdkVersion 27
buildToolsVersion '27.0.1'
targetSdkVersion 27

希望这会有所帮助。