All Projects → li-xiaojun → StateLayout

li-xiaojun / StateLayout

Licence: other
一种无侵入,使用简单,无需修改现有布局,动态切换布局状态(Loading/Error/Empty/Content)的解决方案。

Programming Languages

kotlin
9241 projects
shell
77523 projects

Projects that are alternatives of or similar to StateLayout

PageStatusTransformer
A low invasive state management on Android
Stars: ✭ 12 (-92.05%)
Mutual labels:  status, loading
Loadinglayout
简单实用的页面多状态布局(content,loading,empty,error)
Stars: ✭ 712 (+371.52%)
Mutual labels:  status, loading
Pagestatemanager
manage the loading,emtpy,error state of page, use in xml or just in code
Stars: ✭ 173 (+14.57%)
Mutual labels:  status, loading
css3-loading
20种常见的css3 Loading动画
Stars: ✭ 22 (-85.43%)
Mutual labels:  loading
ServerStatus
A Discord bot to display the status of servers.
Stars: ✭ 73 (-51.66%)
Mutual labels:  status
easy-css-layout
Easy css layout
Stars: ✭ 117 (-22.52%)
Mutual labels:  loading
foo drpc
Foobar2000 music status for Discord Rich Presence!
Stars: ✭ 83 (-45.03%)
Mutual labels:  status
flutter web import js library
Import & use javascript libraries in your flutter web projects
Stars: ✭ 28 (-81.46%)
Mutual labels:  load
yuanful-ui
(微信小程序插件) yuanful-ui是一套可添加到微信小程序内直接使用的免费功能插件,无需重复开发,为用户提供更丰富的服务。
Stars: ✭ 30 (-80.13%)
Mutual labels:  loading
react-native-simplest-hud
The simplest network load indicator of react-native
Stars: ✭ 22 (-85.43%)
Mutual labels:  loading
Fluent-Design
Microsoft's Fluent Design with pure HTML/CSS/JS
Stars: ✭ 36 (-76.16%)
Mutual labels:  loading
gitree
Print a directory tree that shows Git status and ignores files dictated by .gitignore.
Stars: ✭ 32 (-78.81%)
Mutual labels:  status
busy-load
A flexible loading-mask jQuery-plugin
Stars: ✭ 76 (-49.67%)
Mutual labels:  loading
KJNetworkPlugin
🎡A lightweight but powerful Network library. Network Plugin, Support batch and chain operation. 插件版网络架构
Stars: ✭ 43 (-71.52%)
Mutual labels:  loading
python-yamlable
A thin wrapper of PyYaml to convert Python objects to YAML and back
Stars: ✭ 28 (-81.46%)
Mutual labels:  load
Laden
SwiftUI loading indicator view
Stars: ✭ 23 (-84.77%)
Mutual labels:  loading
iakit
无依赖 mini 组件库,只封装了 alert, toast, loading, actionSheet 等使用频率较高的组件。适用于类似 H5 活动页的简单移动端项目,不必为了使用这些组件而引入一个大而全的 UI 库和框架。
Stars: ✭ 38 (-74.83%)
Mutual labels:  loading
status-list
A list of your various social statii.
Stars: ✭ 35 (-76.82%)
Mutual labels:  status
Xamarin.Android.AVLoadingIndicatorView
🔰 AVLoadingIndicatorView is a collection of nice loading animations for Xamarin.Android.
Stars: ✭ 26 (-82.78%)
Mutual labels:  loading
AyLoading
loading...
Stars: ✭ 25 (-83.44%)
Mutual labels:  loading

StateLayout

Simple way to change your layout state, like loading, empty, error. Strong customizitaion, written by Kotlin.

Feature

  • 对已有布局零侵入,无需修改现有布局
  • 支持对Activity, Fragment, View进行状态切换
  • 支持自定义每种状态的布局
  • 暴露失败状态View点击回调
  • 暂时不支持对ConstraintLayout中的View进行状态切换

ScreenShot

StateLayout StateLayout

Gradle

implementation 'com.github.li-xiaojun:StateLayout:Tag'

别忘了添加根地址:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Usage

对Activity/Fragment使用:

val stateLayout = StateLayout(this)
            .wrap(this)
            .showLoading()

对指定View使用:

val layout2 = StateLayout(this)
            .wrap(view)
            .showLoading()

默认是显示内容布局,改变状态的方法:

stateLayout.showLoading()
stateLayout.showContent() //default state
stateLayout.showError()
stateLayout.showEmpty()

在布局中使用:

<com.lxj.statelayout.StateLayout
            android:id="@+id/slInLayout"
            android:layout_marginBottom="40dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                android:id="@+id/tvInLayout"
                android:gravity="center"
                android:text="测试布局中使用"
                android:background="#9f00"
                android:textColor="#fff"
                android:textSize="20sp"
                android:layout_width="match_parent"
                android:layout_height="150dp"/>
        </com.lxj.statelayout.StateLayout>

自定义每种状态对应的布局:

StateLayout(this)
    .config(loadingLayoutId = R.layout.custom_loading, //自定义加载中布局
            errorLayoutId = R.layout.custom_error, //自定义加载失败布局
            emptyLayoutId = R.layout.custom_empty, //自定义数据位为空的布局
            useContentBgWhenLoading = true, //加载过程中是否使用内容的背景,默认false
            enableLoadingShadow = true, //加载过程中是否启用半透明阴影盖在内容上面,默认false
            defaultShowLoading = true, //是否初始显示loading状态,默认显示的是Content
            enableTouchWhenLoading = true, //显示loading状态是否允许触摸,默认false
            noEmptyAndError = true, //是否去除Empty和Error状态,有时候只需要一个Loading状态,可以减少内存,默认false
            showLoadingOnce = false, //是否只显示一次Loading,在某些时候需要,默认false
            retryAction = { //点击errorView的回调
                Toast.makeText(this, "点击了重试", Toast.LENGTH_SHORT).show()
            })
    .wrap(view)
    .showLoading()

也可以全局配置,全局配置适用于所有的实例,但会被每个实例自己的配置覆盖:

StateLayoutConfig.init(...)

在Fragment中使用的时候需要注意下,要将StateLayout作为Fragment的View返回:

private var stateLayout: StateLayout? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    if (fragmentView==null) {
        fragmentView = inflater.inflate(getLayoutId(), container, false)
        stateLayout = StateLayout(context!!)
                .wrap(fragmentView)
                .showLoading()
    }
    return stateLayout
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].