Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I didn't added dependency for androidx CoordinatorLayout and RecyclerView Library but still able to use it

In my project I never added this dependency

implementation androidx.coordinatorlayout:coordinatorlayout but i am still able to use androidx.coordinatorlayout.widget.CoordinatorLayout in my activity_main.xml.

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>

Now I don't understand how am I able to use the CoordinatorLayout in my layout without declaring specified dependency for it.

like image 450
Vivek Singh Avatar asked Sep 11 '19 11:09

Vivek Singh


People also ask

How to add dependency for Recycler view?

Declaring dependencies To add a dependency on RecyclerView, you must add the Google Maven repository to your project.

What is the use of CoordinatorLayout in Android?

CoordinatorLayout is a super-powered FrameLayout . CoordinatorLayout is intended for two primary use cases: As a top-level application decor or chrome layout. As a container for a specific interaction with one or more child views.

Is CoordinatorLayout deprecated?

The CoordinatorLayout. DefaultBehavior annotation is deprecated. Use the CoordinatorLayout. AttachedBehavior interface instead.


1 Answers

I didn't added dependency for androidx CoordinatorLayoutLibrary but stil able to use it

Because you have added implementation 'com.google.android.material:material:1.0.0'

Which includes CoordinatorLayout inside it

No need to add other dependencies for CoordinatorLayout

like image 73
AskNilesh Avatar answered Nov 03 '22 22:11

AskNilesh