ExpandableLayout
ExpandableLayout use ConstraintSet for animate the state changing.
An ExpandableLayout for Android (Api 16+) written in Kotlin. Use ConstraintSet for animate changed. The library also handles configuration changes, so that the view remains expanded/collapsed on configuration change.
Getting Started
- Add it in your root build.gradle at the end of repositories:
- Add the dependency:
Usage
- Define the
el_collapsedHeight
xml attribute (setCollapsedHeight(int height)
method in Java orcollapsedHeight
property in Kotlin) to set the height of view in collapsed state. - Provide unique
id
so that library could restore its state after configuration change.
Then use ExpandableLayout
with any other nested views
Xml snippet:
You can setup this layout programmarically:
Available xml attributes:
If the maximum height of the nested view is less than the collapsed height, then the view will take a static state.
If you want to change the state at runtime (for example, filling content after loading), you can you can use the
collapse / expand
method with the parameter forced
- true.
Available public methods and properties:
-
state: State - Current
State
of thisExpandableLayout
. Read-only property.State.Statical
by default. -
onStateChangeListener: ((oldState: State, newState: State) -> Unit)? - Invoke when
State
changed. -
collapsedHeight: Int - Collapsed height in pixels of view. WARNING! Don't set [collapsedHeight] less, then maximum height of wrapped view.
-
shadowHeight: Int - Height of shadow in pixels when layout is collapsed.
-
showShadow: Boolean - If this parameter is true - show shadow in collapsed 'State'.
-
showButton: Boolean - Show default collapse/expand button. Use if you want make custom button.
-
moreText: CharSequence - Text showing on more button.
-
animationDuration: Int - Duration of animation of collapse/expand. In milliseconds.
-
@ColorInt moreColor: Int - Color of more button (text and arrow).
-
animationSceneRootId: Int - Animation scene root id for transition. Use for animate container for this view. Default is self
-
fun toggle(withAnimation: Boolean = true) - Toggle
ExpandableLayout
state. Ignore ifState.Statical
.
withAnimation
- should it toggle with animation or instantaneously. true by default.
- fun collapse(withAnimation: Boolean = true, forced: Boolean = false) - Collapse
ExpandableLayout
. Ignore ifState.Statical
.
withAnimation
- should it collapse with animation or instantaneously. true by default.
forced
- should it collapse in any state forced. false by default.
- fun expand(withAnimation: Boolean = true, forced: Boolean = false) - Expand
ExpandableLayout
. Ignore ifState.Statical
.
withAnimation
- should it expand with animation or instantaneously. true by default.
forced
- should it expand in any state forced. false by default.