Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skydoves/expandablelayout
🦚 An expandable layout that shows a two-level layout with an indicator.
https://github.com/skydoves/expandablelayout
android android-library collapse expand expandable expandablelayout kotlin skydoves
Last synced: 6 days ago
JSON representation
🦚 An expandable layout that shows a two-level layout with an indicator.
- Host: GitHub
- URL: https://github.com/skydoves/expandablelayout
- Owner: skydoves
- License: apache-2.0
- Created: 2019-09-29T07:56:22.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-12T14:16:24.000Z (over 3 years ago)
- Last Synced: 2025-01-08T01:14:53.042Z (13 days ago)
- Topics: android, android-library, collapse, expand, expandable, expandablelayout, kotlin, skydoves
- Language: Kotlin
- Homepage:
- Size: 365 KB
- Stars: 833
- Watchers: 9
- Forks: 54
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
ExpandableLayout
🦚 An expandable layout that shows a two-level layout with an indicator.
## 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(R.id.button0).setOnClickListener {
toast("button0 clicked")
}
// getting child view using android extension.
expandablelayout.secondLayout.button0.setOnClickListener { toast("button0 clicked") }
```### OnExpandListener
We can listen to the `ExpandableLayout` is expanded or collapsed.
```kotlin
expandablelayout.onExpandListener = object : OnExpandListener {
override fun onExpand(isExpanded: Boolean) {
toast("Expanded : $it")
}
}// or we can listen using a lambda expression.
expandable.setOnExpandListener {
if (it) {
toast("expanded")
} else {
toast("collapse")
}
}
```### ExpandableAnimation
We can customize the expanding and collapsing animation.
```kotlin
ExpandableAnimation.NORMAL
ExpandableAnimation.ACCELERATE
ExpandableAnimation.BOUNCE
```NORMAL | ACCELERATE | BOUNCE
| :---------------: | :---------------: | :---------------: |
| | |## ExpandableLayout Attributes
Attributes | Type | Default | Description
--- | --- | --- | ---
isExpanded | Boolean | false | Expand the second layout initially or not.
parentLayout | layout | default layout | Sets the parent layout.
secondLayout | layout | default layout | Sets the second layout.
duration | Long | 250L | Sets the duration of the spinner animation.
spinner | Drawable | arrow_down | Sets the spinner's drawable.
showSpinner | Boolean | true | Shows the spinner or not.
spinner_animate | Boolean | true | Animates the spinner when expanding or collapse.
spinner_rotation | Integer | -180 | Sets the rotation of the spinner animation.
spinner_size | Dimension | 36dp | Sets the size of the spinner.
spinner_margin | Dimension | 8dp | Sets the margin of the spinner.
spinner_gravity | SpinnerGravity | end | Sets the gravity of the spinner.## Find this library useful? :heart:
Support it by joining __[stargazers](https://github.com/skydoves/ExpandableLayout/stargazers)__ for this repository. :star:
And __[follow](https://github.com/skydoves)__ me for my next creations! 🤩# License
```xml
Copyright 2019 skydoves (Jaewoong Eum)Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```