Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我没有导入回收器视图AndroidX库,但我正在使用它。为什么以及如何工作?_Android_Android Recyclerview_Androidx - Fatal编程技术网

我没有导入回收器视图AndroidX库,但我正在使用它。为什么以及如何工作?

我没有导入回收器视图AndroidX库,但我正在使用它。为什么以及如何工作?,android,android-recyclerview,androidx,Android,Android Recyclerview,Androidx,从我的依赖项中可以看到,我没有导入回收视图Androidx库 androidx.recyclerview:recyclerview:1.0.0 但如下图所示,我可以在布局(activity_main.xml)和MainActivity代码中轻松地使用它 build.gradle(app) android { compileSdkVersion 28 defaultConfig { applicationId "com.example.todolista

从我的依赖项中可以看到,我没有导入回收视图Androidx库

androidx.recyclerview:recyclerview:1.0.0

但如下图所示,我可以在布局(activity_main.xml)和MainActivity代码中轻松地使用它

build.gradle(app)

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.todolistapp"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    // Room
    def room_version = "2.0.0"
    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"

    // ViewModel and LiveData
    def lifecycle_version = "2.0.0"
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
    kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"

    // For Floating Action Button
    implementation 'com.google.android.material:material:1.0.0'
}
是什么导致了这种行为?

根据:

androidx.recyclerview:recyclerview:1.0.0

这意味着材质库已经对RecyclerView具有可传递的依赖关系,您不需要自己手动将其包含在内

我没有导入回收器视图AndroidX库,但我正在使用。为什么以及如何工作

因为您添加了
com.google.android.material:material:1.0.0


如果您已经添加了
com.google.android,则无需添加
androidx.recyclerview:recyclerview:1.0.0
。材质:材质:1.0.0
,我已经尝试和测试过了。
com.google.android.material:material:1.0
也包括
recyclerview
。可能是为了给材质设计带来与
MaterialButton

com.google.android.material:material:1.0.0
包含
RecyclerView
组件一样的外观和感觉,因此您不需要在外部添加它

如果将
com.google.android.material:material:1.0.0
添加到应用程序依赖项中,则无需将
androidx.recyclerview:recyclerview:1.0.0
添加到依赖项中,因为它已包含在材质库中

更多信息

依赖关系{

dependencies{

implementation 'com.google.android.material:material:1.0.0'

}
如果您已经添加了

com.google.android.material:material:1.0.0 或 支持:设计:版本

在以前版本的android recyclerview中,它可以查看设计库,但在Androidx版本中,它可以查看材质库

在依赖项中,则不需要recyclerview依赖项。它已添加到材料/设计库中


有关Android库的详细信息,请参见,以防您的问题是使用与
材料中的版本不同的版本

每次我添加androidx时,我都试图使用alpha版本的
recyclerview
。recyclerview:recyclerview
decenty手动执行代码在构建时工作正常。 但该应用程序不断崩溃,因为它无法从运行时的
recyclerview
的alpha版本中找到我使用的新类

我尝试使用最新的alpha版本的
material
decentcy,但它也依赖于
recyclerview
上的最新稳定版本。因此它没有任何帮助

为了解决这个问题,我从
材料中排除了
recyclerview
体面,并像这样添加了
recyclerview
体面

implementation 'com.android.support:design:your version'

}

除非某个较新版本的RecyclerView,并且您希望手动包含该较新版本。但目前情况并非如此,因此无需立即明确添加。Undr this dependencies com.google.android.material:material:1.0.0,它发生了。这并没有回答问题。为什么这不是答案。我提供答案androidx Recyclerview依赖项是如何工作的。我在这里做错了什么?你到底想知道什么?你可以问我。我可以帮助你。试着阅读。问题是
我没有导入回收器视图androidx库,但我正在使用它。它为什么工作?它是如何工作的?
。那么你告诉我,你在回答这个问题吗?是的,我可以看到它你编辑了答案,这很有帮助,因为我在官方文件中找不到这方面的参考:/@AliEzzatOdeh很高兴听到buddyCan不接受它,因为我不是第一个问这个问题的人,我能为你做的就是投赞成票,从上次开始就已经投了;)@AliEzzatOdeh抱歉,我没有由于队列已满,因此此答案的注释中已标记u。
dependencies{

implementation 'com.google.android.material:material:1.0.0'

}
implementation 'com.android.support:design:your version'

}
implementation("com.google.android.material:material:1.1.0") {
    exclude(group = "androidx.recyclerview", module = "recyclerview")
}
implementation("androidx.recyclerview:recyclerview:1.2.0-alpha04")