Skip to content

Commit 23518e1

Browse files
author
Tear丶残阳
committed
First commit.
1 parent 6d67fdf commit 23518e1

20 files changed

+707
-1
lines changed

README.md

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,75 @@
1-
# stateful.layout
1+
# StatefulLayout
22
方便Android开发者根据不同的状态切换布局的自定义布局,基于FrameLayout,可同时存在多个同状态的子布局,可方便的自定义默认状态的而已,可自定义切换动画。
3+
4+
# 当前最新版本号:[![](https://jitpack.io/v/com.gitee.numeron/stateful.svg)](https://jitpack.io/#com.gitee.numeron/stateful)
5+
6+
### StatefulLayout
7+
* 通过设置`state`的值切换不同的布局,共有4种状态:Empty, Loading, Failure, Success:
8+
```kotlin
9+
try {
10+
statefulLayout.state = State.Loading
11+
val list = getDateList()
12+
adapter.submitList(list)
13+
statefulLayout.state = if(list.isEmpty) State.Empty else State.Success
14+
} catch (throwable: Throwable) {
15+
statefulLayout.state = State.Failure
16+
}
17+
```
18+
* 设置页面中不同状态下的布局:
19+
20+
```xml
21+
<!--引用failure状态下的视图,需要在该视图的根布局中添加app:layout_state="failure"属性-->
22+
<!--同理,也可以引用empty、loading状态的布局,注意添加app:layout_state属性并指定对应的值-->
23+
<StatefulLayout
24+
android:id="@+id/statefulLayout"
25+
android:layout_width="match_parent"
26+
android:layout_height="match_parent"
27+
app:stateful_failure_layout="@layout/state_failure_layout">
28+
29+
<!--默认是success状态-->
30+
<RecyclerView
31+
android:layout_width="match_parent"
32+
android:layout_height="match_parent" />
33+
34+
<!--设置empty状态下的视图-->
35+
<ConstraintLayout
36+
android:layout_width="match_parent"
37+
android:layout_height="match_parent"
38+
app:layout_state="empty" />
39+
40+
<!--设置loading状态下的视图-->
41+
<!--可单独设置某个视图显示或隐藏的动画-->
42+
<ConstraintLayout
43+
android:layout_width="match_parent"
44+
android:layout_height="match_parent"
45+
app:stateful_animation_show="@anim/stateful_loading_show"
46+
app:stateful_animation_hide="@anim/stateful_loading_hide"
47+
app:layout_state="loading" />
48+
49+
</StatefulLayout>
50+
```
51+
* 如果想统一修改除success以外所有状态的默认视图,可在当前正在应用的主题资源中指定:
52+
```xml
53+
<!--默认视图-->
54+
<item="stateful_empty_layout">@layout/state_empty_layout</item>
55+
<item="stateful_loading_layout">@layout/state_loading_layout</item>
56+
<item="stateful_failure_layout">@layout/state_failure_layout</item>
57+
<!--包括默认动画效果-->
58+
<item="stateful_animation_show">@layout/state_show_anim</item>
59+
<item="stateful_animation_hide">@layout/state_hide_anim</item>
60+
```
61+
62+
### 引入
63+
1. 在你的android工程的根目录下的build.gradle文件中的适当的位置添加以下代码:
64+
```groovy
65+
allprojects {
66+
repositories {
67+
...
68+
maven { url 'https://jitpack.io' }
69+
}
70+
}
71+
```
72+
2. 在你的android工程中对应的android模块的build.gradle文件中的适当位置添加以下代码:
73+
```groovy
74+
implementation 'cn.numeron:stateful.layout:latest_version'
75+
```

build.gradle

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
buildscript {
3+
ext {
4+
kotlin_version = '1.4.32'
5+
compile_sdk_version = 30
6+
target_sdk_version = 30
7+
}
8+
repositories {
9+
google()
10+
jcenter()
11+
}
12+
dependencies {
13+
classpath "com.android.tools.build:gradle:4.1.3"
14+
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
15+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
16+
}
17+
}
18+
19+
allprojects {
20+
repositories {
21+
google()
22+
jcenter()
23+
maven { url 'https://jitpack.io' }
24+
}
25+
}
26+
27+
task clean(type: Delete) {
28+
delete rootProject.buildDir
29+
}

gradle.properties

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Project-wide Gradle settings.
2+
# IDE (e.g. Android Studio) users:
3+
# Gradle settings configured through the IDE *will override*
4+
# any settings specified in this file.
5+
# For more details on how to configure your build environment visit
6+
# http://www.gradle.org/docs/current/userguide/build_environment.html
7+
# Specifies the JVM arguments used for the daemon process.
8+
# The setting is particularly useful for tweaking memory settings.
9+
org.gradle.jvmargs=-Xmx2048m
10+
# When configured, Gradle will run in incubating parallel mode.
11+
# This option should only be used with decoupled projects. More details, visit
12+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13+
# org.gradle.parallel=true
14+
# AndroidX package structure to make it clearer which packages are bundled with the
15+
# Android operating system, and which are packaged with your app"s APK
16+
# https://developer.android.com/topic/libraries/support-library/androidx-rn
17+
android.useAndroidX=true
18+
# Automatically convert third-party libraries to use AndroidX
19+
android.enableJetifier=true
20+
# Kotlin code style for this project: "official" or "obsolete":
21+
kotlin.code.style=official

gradle/wrapper/gradle-wrapper.jar

53.1 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Mon Mar 29 16:57:09 CST 2021
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

gradlew

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)