【问题标题】:I didn't added dependency for androidx CoordinatorLayout and RecyclerView Library but still able to use it我没有添加对 androidx CoordinatorLayout 和 RecyclerView 库的依赖,但仍然可以使用它
【发布时间】:2019-09-11 11:30:09
【问题描述】:

在我的项目中,我从未添加过此依赖项

implementation androidx.coordinatorlayout:coordinatorlayout 但我仍然可以在我的activity_main.xml 中使用androidx.coordinatorlayout.widget.CoordinatorLayout

build.gradle

apply plugin: 'com.android.application'

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

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

    //Google material design
    implementation 'com.google.android.material:material:1.0.0'
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_height="192dp"
        android:layout_width="match_parent">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:toolbarId="@+id/toolbar"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
            app:contentScrim="?attr/colorPrimary">


            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_height="?attr/actionBarSize"
                android:layout_width="match_parent">

            </androidx.appcompat.widget.Toolbar>

        </com.google.android.material.appbar.CollapsingToolbarLayout>

    </com.google.android.material.appbar.AppBarLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

现在我不明白如何在我的布局中使用 CoordinatorLayout 而不声明它的指定依赖项。

【问题讨论】:

  • 因为implementation 'com.google.android.material:material:1.0.0'包含CoordinatorLayout不需要为CoordinatorLayout添加其他dependencies

标签: java android xml android-gradle-plugin androidx


【解决方案1】:

我没有添加对 androidx CoordinatorLayoutLibrary 的依赖,但仍然可以使用它

因为你加了implementation 'com.google.android.material:material:1.0.0'

其中包含CoordinatorLayout

CoordinatorLayout不用再添加其他dependencies

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-22
  • 2010-11-28
  • 2020-07-25
  • 2019-12-16
相关资源
最近更新 更多