【问题标题】:Recyclerview preview showing grey screen with android.support.v7.widget.RecyclerView in centerRecyclerview 预览显示灰屏,android.support.v7.widget.RecyclerView 居中
【发布时间】:2018-08-07 09:59:26
【问题描述】:

我正在尝试将 Recyclerview 添加到我的活动布局中,但布局预览显示 this。我浏览了所有可能的答案,我可以找到并尝试做类似的事情

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

我的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'

}

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

我无法弄清楚问题所在。请帮帮我。

【问题讨论】:

标签: android android-studio android-recyclerview android-coordinatorlayout


【解决方案1】:

尝试在 Android Studio 的“文件”中执行“Invalidate Cache / Restart”。

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

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

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

【讨论】:

  • 我尝试按照你说的做,但没有解决我的问题。
【解决方案2】:

试试这个:

compileSdkVersion 27
buildToolsVersion '27.0.1'
targetSdkVersion 27

希望这会有所帮助。

【讨论】:

  • 这确实对我有用....但也必须更改所有依赖项...只是我有一个疑问...如果将 targetSdkVersion 更改为 27 会影响应用程序,如果它安装在 oreo 上基于安卓手机?? @Faysal
【解决方案3】:

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

【讨论】:

    【解决方案4】:

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

    【讨论】:

      猜你喜欢
      • 2016-01-25
      • 2016-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-18
      • 1970-01-01
      相关资源
      最近更新 更多