Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/XuDaojie/MultiStateView

通用状态切换视图(已停止维护)
https://github.com/XuDaojie/MultiStateView

Last synced: about 1 month ago
JSON representation

通用状态切换视图(已停止维护)

Awesome Lists containing this project

README

        

MultiStateView
==============
[![JitPack](https://jitpack.io/v/XuDaojie/MultiStateView.svg)](https://jitpack.io/#XuDaojie/MultiStateView)
[![API](https://img.shields.io/badge/API-8%2B-orange.svg?style=flat)](https://android-arsenal.com/api?level=8)
[![Method and size](https://img.shields.io/badge/Methods and size-64 | 7 KB-e91e63.svg)](http://www.methodscount.com/?lib=com.github.XuDaojie%3AMultiStateView%3Av2.2.2)

[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-MultiStateView-green.svg?style=true)](https://android-arsenal.com/details/1/4386)

参考[Kennyc1012/MultiStateView](https://github.com/Kennyc1012/MultiStateView)这个这个写的,1.0版本只是在这个上面加了默认布局,以及修正了在设计器中无法预览的问题

2.0是自己写的,主要增加了自定义状态,当然,核心原理还是那样

用于切换不同View的各种状态,默认包含`Content`,`Empty`,`Fail`,`Loading` 4个状态,并且支持添加其他状态

处理了`Loading`显示时间很短立刻切换到其他状态时看起来好像`Loading`界面闪了一下

![screenshot](https://github.com/XuDaojie/MultiStateView/blob/develop/art/MultiStateView.gif)

## Using MultiStateView
### Layout
``` xml

```

可以通过以下属性自定义可状态下的视图
``` xml

```
> Tips

> 由于`MultiStateView`继承于`FrameLayout`,直接子布局只能有一个,其他的不显示.

### 主要方法
``` java
public void setViewState(int state) // 设置视图状态
public int getViewState() // 获得当前状态
public View getView(int state) // 获得指定状态的视图
public void addViewForStatus(int status, int resLayoutID) // 增加状态
public void setOnInflaterListener(OnInflateListener onInflateListener) // 各状态Layout inflate时触发(除了CONTENT)
```

> Tips

> 1. 当从`Loading`状态切换到其他状态时,如果`Loading`持续时间低于**600ms**则会延迟**600ms**切换

> 2. 除了`CONTENT`以外的状态**Layout**都是在首次调用`setViewState`后才会**inflate**,所以设置监听事件的话需要状态修改完成后设置,或者调用`setOnInflaterListener`进行设置

### 常量
``` java
public static final int STATE_CONTENT = 10001;
public static final int STATE_LOADING = 10002;
public static final int STATE_EMPTY = 10003;
public static final int STATE_FAIL = 10004;
```

### 代码
具体代码可以看[MultiStateFragment](https://github.com/XuDaojie/MultiStateView/blob/master/app/src/main/java/me/xdj/multistateview/MultiStateFragment.java)

## Including in your project
要将**MultiStateView**引入你的项目,需要修改你的**build.gradle**

### Add repository
``` groovy
repositories {
maven { url 'https://jitpack.io' }
}
```
### Add dependency
``` groovy
dependencies {
compile 'com.github.XuDaojie:MultiStateView:v2.2.3'
}
```

## 喝水不忘挖井人
[Kennyc1012/MultiStateView](https://github.com/Kennyc1012/MultiStateView)

[android.support.v4.widget.ContentLoadingProgressBar](https://android.googlesource.com/platform/frameworks/support/+/refs/heads/master/v4/java/android/support/v4/widget/ContentLoadingProgressBar.java)

## License
Copyright XuDaojie

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.