skydoves / ExpandableLayout

🦚 An expandable layout that shows a two-level layout with an indicator.
Apache License 2.0
825 stars 54 forks source link
android android-library collapse expand expandable expandablelayout kotlin skydoves

ExpandableLayout


🦚 An expandable layout that shows a two-level layout with an indicator.


License API Travis Android Weekly Javadoc

## Including in your project [![Maven Central](https://img.shields.io/maven-central/v/com.github.skydoves/expandablelayout.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.github.skydoves%22%20AND%20a:%22expandablelayout%22) [![Jitpack](https://jitpack.io/v/skydoves/ExpandableLayout.svg)](https://jitpack.io/#skydoves/ExpandableLayout) ### Gradle Add below codes to your **root** `build.gradle` file (not your module build.gradle file). ```gradle allprojects { repositories { mavenCentral() } } ``` And add a dependency code to your **module**'s `build.gradle` file. ```gradle dependencies { implementation "com.github.skydoves:expandablelayout:1.0.7" } ``` ## Usage Add following XML namespace inside your XML layout file. ```gradle xmlns:app="http://schemas.android.com/apk/res-auto" ``` ### ExpandableLayout Here is a basic example of implementing `ExpandableLayout`. ```gradle ``` ### Create using builder class We can create an instance of `ExpandableLayout` using the builder class. ```kotlin val myExpandableLayout = expandableLayout(context) { setParentLayoutResource(R.layout.layout_parent) setSecondLayoutResource(R.layout.layout_second) setShowSpinner(true) setSpinnerAnimate(true) setSpinnerMargin(12f) setSpinnerRotation(90) setDuration(200) setOnExpandListener { toast("is expanded : $it") } } ``` ### Expand and Collapse We can expand and collapse using the below methods. ```kotlin expandablelayout.expand() // expand the second layout with indicator animation. expandablelayout.collapse() // collapse the second layout with indicator animation. ``` ### ParentLayout and SecondLayout We can get the `parentLayout` and `secondLayout` of the `ExpandableLayout`.
And we can access child views of them. ```kotlin expandablelayout.parentLayout.setOnClickListener { toast("the parent layout is clicked!") } expandablelayout.secondLayout.setOnClickListener { toast("the second layout is clicked!") } // getting child view using findViewById. expandablelayout.secondLayout.findViewById