android - Recyclerview 显示灰色区域

标签 android android-recyclerview

RecyclerView 没有显示在下面的图片中,我找不到 任何解决方案。 我尝试了什么:

  • 重建
  • 清理项目
  • 使缓存无效

enter image description here

我的build.gradle(Module:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.user.myapplication"
        minSdkVersion 15
        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'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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:recyclerview-v7:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
}

这就是图中显示的activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:padding="8dp">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    </android.support.v7.widget.RecyclerView>

</LinearLayout>

最佳答案

好吧,28.0.0 支持库-API 依赖性实际上更好 Android Studio 3.2.0 及更高版本,这是因为AndroidX 正在迁移。

因此,升级 Android Studio 会有所帮助,因为您已经添加了 RecyclerView 依赖项,并且预览没有问题,也没有显示任何错误。

关于android - Recyclerview 显示灰色区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52611446/

相关文章:

java - 如何将RecyclerView添加到LinearLayout(高度问题)

android - 从导入的库访问项目中的 jar - gradle/android studio

java - 如何在android中使用Retrofit登录Django服务器?

带有 Facebook 登录示例的 java.lang.RuntimeException

android - RecyclerView 和 CardView Click 监听器实现

android - Firebase 数据库按升序分页

Android- ScrollView 和水平回收 View 之间的滑动冲突

java - : java/nio/file/Paths; 解析失败

Android adb 不允许我输入命令

java - 用 Glide 加载图像很慢