{"id":21823491,"url":"https://github.com/limedroid/xstatecontroller","last_synced_at":"2025-04-14T04:24:14.251Z","repository":{"id":217140458,"uuid":"79701242","full_name":"limedroid/XStateController","owner":"limedroid","description":"状态控制机","archived":false,"fork":false,"pushed_at":"2017-02-07T03:43:32.000Z","size":106,"stargazers_count":58,"open_issues_count":2,"forks_count":16,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T18:21:22.576Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/limedroid/XStateController","language":"Java","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/limedroid.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}},"created_at":"2017-01-22T07:20:49.000Z","updated_at":"2023-04-03T09:52:48.000Z","dependencies_parsed_at":"2024-01-14T20:29:29.133Z","dependency_job_id":"1dc69c02-ea20-497a-bba1-4f9537d8ca7a","html_url":"https://github.com/limedroid/XStateController","commit_stats":null,"previous_names":["limedroid/xstatecontroller"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limedroid%2FXStateController","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limedroid%2FXStateController/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limedroid%2FXStateController/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limedroid%2FXStateController/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/limedroid","download_url":"https://codeload.github.com/limedroid/XStateController/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248820125,"owners_count":21166605,"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":[],"created_at":"2024-11-27T17:32:29.114Z","updated_at":"2025-04-14T04:24:14.229Z","avatar_url":"https://github.com/limedroid.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"#XStateController\r\n`StateController`顾名思义：状态控制机，用作几个状态的切换。该控件可以在`Loading` \u0026 `Empty` \u0026 `Error`\u0026 `Content`四个状态的自定义动画切换。\n\n[![](https://jitpack.io/v/limedroid/XStateController.svg)](https://jitpack.io/#limedroid/XStateController)\n\n## 特性\n\n* 不受布局层级的控制，可任意大小、任意层级\n* 支持xml设置状态布局资源\n* 支持java代码设置状态布局\n* 可自定义动画切换状态\n* 可注册状态切换回调\n* 支持异常情况的状态保存\n* 可以设置一个或几个状态，无需全部状态设置\n\n## 集成步骤\n\n### step1 \n\n在根项目的`build.gradle`文件中添加\n\n```groovy\nallprojects {\n\t\trepositories {\n\t\t\t...\n\t\t\tmaven { url 'https://jitpack.io' }\n\t}\n}\n```\n\n### step2\n\n添加依赖\n\n```groovy\ndependencies {\n\t   compile 'compile 'com.github.limedroid:XStateController:v1.1.0'\n}\n```\n\n![](screenshot.png)\n\n## 使用\n\n```java\n \u003ccn.droidlover.xstatecontroller.XStateController\n        android:id=\"@+id/controller\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        app:x_emptyLayoutId=\"@layout/view_empty\"\u003e\n       \n\n        \u003cTextView\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"match_parent\"\n            android:background=\"#854678\"\n            android:gravity=\"center\"\n            android:text=\"Content\"\n            android:textColor=\"@android:color/white\"\n            android:textSize=\"28sp\" /\u003e\n\n    \u003c/cn.droidlover.xstatecontroller.XStateController\u003e\n```\n\n### 说明\n\n* 当`XStateController`仅有一个子view（ViewGroup）时，该子view则为`ContentView`\n* 可以通过xml属性设置布局，也可代码设置\n\n### attrs设置状态布局资源\n\n```xml\n \u003cattr name=\"x_contentLayoutId\" format=\"reference\" /\u003e\n \u003cattr name=\"x_loadingLayoutId\" format=\"reference\" /\u003e\n \u003cattr name=\"x_emptyLayoutId\" format=\"reference\" /\u003e\n \u003cattr name=\"x_errorLayoutId\" format=\"reference\" /\u003e\n```\n\n* `x_contentLayoutId`设置内容布局资源\n* `x_loadingLayoutId`设置加载中状态的布局资源\n* `x_emptyLayoutId`设置空状态的布局资源\n* `x_errorLayoutId`设置错误状态的布局资源\n\n### 常见api\n\n设置各状态的布局资源\n\n```java\nloadingView(loadingView)；  //设置加载中的view\nemptyView(emptyView)； \t//设置空view\nerrorView(errorView)；\t//设置errorView\ncontentView(contentView); //设置contentView\n```\n\n状态切换\n\n```java\nshowLoading();\t\t//切换到loading状态\nshowError();\t\t//切换到error状态\nshowEmpty();\t\t//切换到empty状态\nshowContent();\t\t//切换到content状态\n```\n\n注册状态切换回调\n\n```java\nregisterStateChangeListener(xx);\n```\n\n回调的定义\n\n```java\npublic interface OnStateChangeListener {\n\t\t//状态切换时回调，oldState当前状态,newState目标状态\n        void onStateChange(int oldState, int newState);\n\t\t//动画，可自定义切换动画\n        void animationState(View exitView, View enterView);\n    }\n```\n\n使用时可直接继承*SimpleStateChangeListener*\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimedroid%2Fxstatecontroller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flimedroid%2Fxstatecontroller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimedroid%2Fxstatecontroller/lists"}