Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

👉无预设状态,只提供切换操作,并只保有当前显示的状态视图。

License

Notifications You must be signed in to change notification settings

Chooongg/StateLayout

Repository files navigation

StateLayout

  • 基于 2022年1月1日 Patch 2 和 AndroidX 构建.
  • 请同时阅读 issuesreleases.

[ ENGLISH ]

截图

特点

  • 扩展性良好
  • 以class类作为状态码
  • 完全可自定义的状态
  • 支持自定义参数
  • 支持动画
  • 完全可自定义的动画
  • 支持子视图的可见性策略
  • 对 AppBarLayout Lift 支持
  • 低耦合

安装

Gradle

在模块的 "build.gradle" 文件中,将此实现语句添加到 "dependencies" 部分:

dependencies {
 implementation "com.chooongg.widget:statelayout:$version"
}

如何使用

1. 用于布局XML

将 StateLayout 添加到布局 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支持配置visibilityStrategy属性,该属性用于控制状态切换期间的显示和隐藏策略

<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>

show 方法可用于切换 StateLayout 的状态

// show ProgressState
stateLayout.show(ProgressState::class)
// show Content
stateLayout.ShowContent()

设置点击重试事件的侦听器

stateLayout.setOnRetryEventListener { currentState: KClass<out AbstractState> ->
 // do something
}

设置状态更改的侦听器

stateLayout.setOnStateChangedListener { currentState: KClass<out AbstractState> ->
 // do something
}

2. 在代码中使用

// 绑定 Activity
val stateLayout = StateLayout.bind(activity)
// 绑定 Fragment
val stateLayout = StateLayout.bind(fragment)
// 绑定 View
val stateLayout = StateLayout.bind(view)

R8 / 混淆

如果您正在使用R8,则会自动包含压缩和混淆规则。

ProGuard 用户必须手动添加中的选项[consumer-rules.pro].

许可证

根据 Apache 许可证 2.0 版获得许可,单击此处获取完整许可证

About

👉无预设状态,只提供切换操作,并只保有当前显示的状态视图。

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /