[ 中文 ]
- good scalability
- using the class as the status code
- fully customizable states
- support for custom parameters
- support for animation
- fully customizable animation
- support for child view visibility strategy
- support for AppBarLayout Lift
- low coupling
On your module's build.gradle file add this implementation statement to the dependencies
section:
dependencies {
implementation "com.chooongg.widget:statelayout:$version"
}adding a state layout to layout xml
<com.chooongg.widget.stateLayout.StateLayout
android:id="@+id/stateLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- ChildView -->
<!-- ChildView -->
<!-- ChildView -->
</com.chooongg.widget.stateLayout.StateLayout>ChildView supports configuring the visibilityStrategy attribute, which is used to control the display and hide policies during state switching
<com.chooongg.widget.stateLayout.StateLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- show when the state is ContentState, default -->
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_visibilityStrategy="content"/>
<!-- show as long as the status is non ContentState -->
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_visibilityStrategy="other"/>
<!-- show as long as the ContentState exists -->
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_visibilityStrategy="otherIgnoreContent"/>
<!-- always show regardless of any status -->
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_visibilityStrategy="always"/>
</com.chooongg.widget.stateLayout.StateLayout>The show method can be used to switch the state of StateLayout
// show ProgressState
stateLayout.show(ProgressState::class)
// show Content
stateLayout.ShowContent()set the on retry event listener
stateLayout.setOnRetryEventListener { currentState: KClass<out AbstractState> ->
// do something
}set the on state changed listener
stateLayout.setOnStateChangedListener { currentState: KClass<out AbstractState> ->
// do something
}// bind Activity
val stateLayout = StateLayout.bind(activity)
// bind Fragment
val stateLayout = StateLayout.bind(fragment)
// bind View
val stateLayout = StateLayout.bind(view)If you are using R8 the shrinking and obfuscation rules are included automatically.
ProGuard users must manually add the options from[consumer-rules.pro].
Licensed under the Apache License, Version 2.0, click here for the full license.


