├── .gitignore ├── .idea ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── king │ │ └── bird │ │ └── multiplelayout │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── king │ │ │ └── bird │ │ │ └── multiplelayout │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── king │ └── bird │ └── multiplelayout │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── multipleview ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── king │ │ └── bird │ │ └── multipleview │ │ └── MultipleLayout.java │ └── res │ ├── layout │ ├── layout_empty_view.xml │ ├── layout_error_view.xml │ ├── layout_loading_view.xml │ └── layout_network_view.xml │ ├── mipmap-xhdpi │ ├── ic_error.png │ ├── ic_no_data.png │ └── ic_no_network.png │ └── values │ ├── attrs.xml │ ├── colors.xml │ ├── ids.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pengMaster/MultipleLayout/c2428576c154fec72e5509086580f2baea2832b7/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |

最简单的状态切换布局

3 | 4 |

5 | 6 | 英文说明 7 | 8 |

9 | 10 | ### 功能简介 11 | 12 | - 正在加载数据 13 | - 数据加载失败 14 | - 数据加载为空 15 | - 网络加载失败 16 | - 重试点击事件 17 | - 支持自定义布局 18 | 19 | 20 | ### 效果图展示 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | ### 最简单的使用方式 33 | 34 | 1.Add it in your root build.gradle at the end of repositories: 35 | 36 | ```java 37 | allprojects { 38 | repositories { 39 | ... 40 | maven { url 'https://jitpack.io' } 41 | } 42 | } 43 | 44 | ``` 45 | 46 | 2.Add the dependency 47 | 48 | ```java 49 | dependencies { 50 | implementation 'com.github.pengMaster:MultipleLayout:1.0.0' 51 | } 52 | 53 | ``` 54 | 3.在布局中添加 55 | 56 | ```java 57 | 58 | 62 | 63 | 64 | 70 | 71 | 72 | 73 | 74 | ``` 75 | ``` 76 | 注意: MultipleLayout 可做为没有标题栏的最外层布局,内部可包裹任何内容 77 | ``` 78 | 79 | 4.代码中使用 80 | 81 | ```java 82 | //重试点击事件 83 | mMultipleLayout.setOnRetryClickListener { 84 | //模拟网络请求 85 | Toast.makeText(this@MainActivity,"正在加载。。",Toast.LENGTH_SHORT).show() 86 | } 87 | //数据为空 88 | mMultipleLayout.showEmpty() 89 | //加载失败 90 | mMultipleLayout.showError() 91 | //正在加载 92 | mMultipleLayout.showLoading() 93 | //网络加载失败 94 | mMultipleLayout.showNoNetwork() 95 | //显示内容 96 | mMultipleLayout.showContent() 97 | 98 | 99 | ``` 100 | 101 | 102 | ### 扩展功能 103 | 104 | 1.自定义状态布局 105 | 106 | ```java 107 | 112 | app:emptyView="@layout/layout_empty_view" 113 | app:errorView="@layout/layout_error_view" 114 | app:loadingView="@layout/layout_loading_view" 115 | app:noNetworkView="@layout/layout_network_view"> 116 | 117 | 118 | ``` 119 | 120 | 2.代码引入布局 121 | 122 | ```java 123 | //数据为空 124 | showEmpty(int layoutId, ViewGroup.LayoutParams layoutParams) 125 | showEmpty(View view, ViewGroup.LayoutParams layoutParams) 126 | //加载失败 127 | showError(int layoutId, ViewGroup.LayoutParams layoutParams) 128 | showError(View view, ViewGroup.LayoutParams layoutParams) 129 | //正在加载 130 | showLoading(int layoutId, ViewGroup.LayoutParams layoutParams) 131 | showLoading(View view, ViewGroup.LayoutParams layoutParams) 132 | //网络加载失败 133 | void showNoNetwork(int layoutId, ViewGroup.LayoutParams layoutParams) 134 | showNoNetwork(View view, ViewGroup.LayoutParams layoutParams) 135 | 136 | ``` 137 | 3.扩展 138 | ``` 139 | 后续添加各种弹框 140 | ``` 141 | 142 | ### 参与贡献 143 | 144 | 1. Fork 本项目 145 | 2. 新建 Feat_xxx 分支 146 | 3. 提交代码 147 | 4. 新建 Pull Request 148 | 149 | 150 | ### github地址 151 | 152 | - 项目地址:https://github.com/pengMaster/MultipleLayout 153 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 28 9 | defaultConfig { 10 | applicationId "king.bird.multiplelayout" 11 | minSdkVersion 15 12 | targetSdkVersion 28 13 | versionCode 1 14 | versionName "1.0" 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(dir: 'libs', include: ['*.jar']) 27 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 28 | implementation 'com.android.support:appcompat-v7:28.0.0' 29 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 30 | testImplementation 'junit:junit:4.12' 31 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 33 | 34 | implementation project(':multipleview') 35 | 36 | } 37 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/king/bird/multiplelayout/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package king.bird.multiplelayout 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("king.bird.multiplelayout", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/king/bird/multiplelayout/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package king.bird.multiplelayout 2 | 3 | import android.support.v7.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.widget.Toast 6 | import kotlinx.android.synthetic.main.activity_main.* 7 | 8 | class MainActivity : AppCompatActivity() { 9 | 10 | override fun onCreate(savedInstanceState: Bundle?) { 11 | super.onCreate(savedInstanceState) 12 | setContentView(R.layout.activity_main) 13 | 14 | //重试点击事件 15 | mMultipleLayout.setOnRetryClickListener { 16 | //模拟网络请求 17 | Toast.makeText(this@MainActivity,"正在加载。。",Toast.LENGTH_SHORT).show() 18 | } 19 | 20 | //数据为空 21 | mBtnNoData.setOnClickListener { mMultipleLayout.showEmpty() } 22 | //加载失败 23 | mBtnLoadError.setOnClickListener { mMultipleLayout.showError() } 24 | //正在加载 25 | mBtnLoading.setOnClickListener { mMultipleLayout.showLoading() } 26 | //网络加载失败 27 | mBtnNetError.setOnClickListener { mMultipleLayout.showNoNetwork() } 28 | //显示内容 29 | mBtnShowContent.setOnClickListener { mMultipleLayout.showContent() } 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 14 | 15 | 16 | 22 | 23 | 24 | 25 |