{"id":20958514,"url":"https://github.com/junixapp/statelayout","last_synced_at":"2025-06-24T21:07:38.634Z","repository":{"id":108524990,"uuid":"149069877","full_name":"junixapp/StateLayout","owner":"junixapp","description":"一种无侵入，使用简单，无需修改现有布局，动态切换布局状态(Loading/Error/Empty/Content)的解决方案。","archived":false,"fork":false,"pushed_at":"2022-05-13T07:35:13.000Z","size":1763,"stargazers_count":180,"open_issues_count":1,"forks_count":22,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-14T06:43:20.855Z","etag":null,"topics":["load","loading","loadinglayout","statelayout","status"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/junixapp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-09-17T04:43:24.000Z","updated_at":"2025-03-27T19:12:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"76ccb1aa-97e2-47b3-a6de-62a3dd17e73a","html_url":"https://github.com/junixapp/StateLayout","commit_stats":null,"previous_names":["junixapp/statelayout"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/junixapp/StateLayout","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junixapp%2FStateLayout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junixapp%2FStateLayout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junixapp%2FStateLayout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junixapp%2FStateLayout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/junixapp","download_url":"https://codeload.github.com/junixapp/StateLayout/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junixapp%2FStateLayout/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261756769,"owners_count":23205159,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["load","loading","loadinglayout","statelayout","status"],"created_at":"2024-11-19T01:47:59.314Z","updated_at":"2025-06-24T21:07:38.608Z","avatar_url":"https://github.com/junixapp.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StateLayout\nSimple way to change your layout state, like loading, empty, error. Strong customizitaion, written by Kotlin.\n\n\n# Feature\n- 对已有布局零侵入，无需修改现有布局\n- 支持对Activity, Fragment, View进行状态切换\n- 支持自定义每种状态的布局\n- 暴露失败状态View点击回调\n- 暂时不支持对ConstraintLayout中的View进行状态切换\n\n# ScreenShot\n![StateLayout](/screenshot/preview.gif)\n![StateLayout](/screenshot/fragment.gif)\n\n\n# Gradle\n[![](https://jitpack.io/v/li-xiaojun/StateLayout.svg)](https://jitpack.io/#li-xiaojun/StateLayout)\n```\nimplementation 'com.github.li-xiaojun:StateLayout:Tag'\n```\n别忘了添加根地址：\n```\nallprojects {\n    repositories {\n        ...\n        maven { url 'https://jitpack.io' }\n    }\n}\n```\n\n\n# Usage\n对Activity/Fragment使用:\n```kotlin\nval stateLayout = StateLayout(this)\n            .wrap(this)\n            .showLoading()\n```\n\n对指定View使用:\n```kotlin\nval layout2 = StateLayout(this)\n            .wrap(view)\n            .showLoading()\n```\n\n默认是显示内容布局，改变状态的方法:\n```kotlin\nstateLayout.showLoading()\nstateLayout.showContent() //default state\nstateLayout.showError()\nstateLayout.showEmpty()\n```\n\n在布局中使用:\n```\n\u003ccom.lxj.statelayout.StateLayout\n            android:id=\"@+id/slInLayout\"\n            android:layout_marginBottom=\"40dp\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"wrap_content\"\u003e\n            \u003cTextView\n                android:id=\"@+id/tvInLayout\"\n                android:gravity=\"center\"\n                android:text=\"测试布局中使用\"\n                android:background=\"#9f00\"\n                android:textColor=\"#fff\"\n                android:textSize=\"20sp\"\n                android:layout_width=\"match_parent\"\n                android:layout_height=\"150dp\"/\u003e\n        \u003c/com.lxj.statelayout.StateLayout\u003e\n```\n\n自定义每种状态对应的布局:\n```kotlin\nStateLayout(this)\n    .config(loadingLayoutId = R.layout.custom_loading, //自定义加载中布局\n            errorLayoutId = R.layout.custom_error, //自定义加载失败布局\n            emptyLayoutId = R.layout.custom_empty, //自定义数据位为空的布局\n            useContentBgWhenLoading = true, //加载过程中是否使用内容的背景，默认false\n            enableLoadingShadow = true, //加载过程中是否启用半透明阴影盖在内容上面，默认false\n            defaultShowLoading = true, //是否初始显示loading状态，默认显示的是Content\n            enableTouchWhenLoading = true, //显示loading状态是否允许触摸，默认false\n            noEmptyAndError = true, //是否去除Empty和Error状态，有时候只需要一个Loading状态，可以减少内存，默认false\n            showLoadingOnce = false, //是否只显示一次Loading，在某些时候需要，默认false\n            retryAction = { //点击errorView的回调\n                Toast.makeText(this, \"点击了重试\", Toast.LENGTH_SHORT).show()\n            })\n    .wrap(view)\n    .showLoading()\n```\n\n也可以全局配置，全局配置适用于所有的实例，但会被每个实例自己的配置覆盖：\n```kotlin\nStateLayoutConfig.init(...)\n```\n\n在Fragment中使用的时候需要注意下，要将StateLayout作为Fragment的View返回：\n```kotlin\nprivate var stateLayout: StateLayout? = null\noverride fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {\n    if (fragmentView==null) {\n        fragmentView = inflater.inflate(getLayoutId(), container, false)\n        stateLayout = StateLayout(context!!)\n                .wrap(fragmentView)\n                .showLoading()\n    }\n    return stateLayout\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunixapp%2Fstatelayout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjunixapp%2Fstatelayout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunixapp%2Fstatelayout/lists"}