StatusLayout,一個在Android上可切換資料狀態的佈局
原始碼: https://github.com/F1ReKing/StatusLayout
一個在Android上可切換資料狀態的佈局,包含了載入佈局,空資料佈局,錯誤佈局
特性
- 支援鏈式呼叫
- 支援動態切換載入,空資料,錯誤,內容佈局
- 懶載入佈局,沒有佈局層疊問題
- 支援點選監聽事件處理
預覽圖

statusLayout.gif
引入
Step 1. Add the JitPack repository to your build file
allprojects { repositories { ... maven { url 'https://www.jitpack.io' } } }
Step 2. Add the dependency
dependencies { compile 'com.github.F1ReKing:StatusLayout:x.y.z' }
Current latest version: 1.2.1
使用
快速用法
-
kotlin用法
private lateinit var mStatusLayout: StatusLayout mStatusLayout = StatusLayout.Builder(congtentLayout) .setOnStatusClickListener(object : StatusClickListener { override fun onEmptyClick(view: View) { } override fun onErrorClick(view: View) { } }) .build()
-
Java 用法
private StatusLayout mStatusLayout; mStatusLayout = new StatusLayout.Builder(congtentLayout).setOnStatusClickListener(new StatusClickListener() { @Override public void onEmptyClick(View view) { } @Override public void onErrorClick(View view) { } }).build();
-
統一呼叫
//顯示內容佈局 mStatusLayout.showContentLayout(); //顯示載入中佈局 mStatusLayout.showLoadingLayout(); //顯示資料空佈局 mStatusLayout.showEmptyLayout(); //顯示資料錯誤佈局 mStatusLayout.showErrorLayout();
API
-
配置佈局
注意:自定義layout中id必須與lib中一致
方法名 說明 layout中ID setOnLoadingLayout(@LayoutRes loadingLayoutID: Int) 配置載入佈局 tv_status_loading setOnLoadingLayout(loadingLayout: View) 配置載入佈局 tv_status_loading setOnEmptyLayout(@LayoutRes emptyLayoutID: Int) 配置資料空佈局 iv_status_empty<br />tv_status_empty<br />tv_click_empty setOnEmptyLayout(emptyLayout: View) 配置資料空佈局 iv_status_empty<br />tv_status_empty<br />tv_click_empty setOnErrorLayout(@LayoutRes errorLayoutID: Int) 配置資料錯誤佈局 iv_status_error<br />tv_status_error<br />tv_click_error setOnErrorLayout(errorLayout: View) 配置資料錯誤佈局 iv_status_error<br />tv_status_error<br />tv_click_error -
配置文字、字型顏色等屬性
方法名 說明 setOnLoadingText(loadingText: String) 設定載入提示文字 setOnLoadingtext(@StringRes loadingTextStringRes: Int) 設定載入提示文字 setOnLoadingTextColor(loadingTextColorRes: Int) 設定載入提示文字顏色 setOnEmptyText(emptyText: String) 設定資料空提示文字 setOnEmptyText(@StringRes emptyTextStringRes: Int) 設定資料空提示文字 setOnEmptyClickText(emptyClickText: String) 設定資料空點選文字 setOnEmptyClickText(@StringRes emptyClickTextStringRes: Int) 設定資料空點選文字 setOnEmptyTextColor(emptyTextStringRes: Int) 設定資料空提示文字顏色 setOnEmptyClickTextColor(emptyClickTextColorRes: Int) 設定資料空點選文字顏色 setOnErrorText(errorText: String) 設定資料錯誤提示文字 setOnErrorText(@StringRes errorTextStringRes: Int) 設定資料錯誤提示文字 setOnErrorClickText(errorClickText: String) 設定資料錯誤點選文字 setOnErrorClickText(@StringRes errorClickTextStringRes: Int) 設定資料錯誤點選文字 setOnErrorTextColor(errorTextStringRes: Int) 設定資料錯誤提示文字顏色 setOnErrorClickTextColor(errorClickTextColorRes: Int) 設定資料錯誤點選文字顏色 -
配置圖片
方法名 說明 setOnEmptyImg(@DrawableRes emptyImgID: Int) 設定資料空圖片 setOnErrorImg(@DrawableRes errorImgID: Int) 設定資料錯誤圖片
版本開發記錄
v1.2.1
- 修改方法名,避免與kotlin語法衝突
v1.2.0
- 添加了能修改載入佈局提示字型顏色
v1.1.1
- 更改包名
v1.1.0
- 新增修改字型顏色
v1.0.1
- 優化佈局和功能
v1.0
- 初始化提交
- 支援載入佈局,空資料佈局,出錯佈局
License
Copyright 2018 F1ReKing. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.