一个通用状态切换视图

1,656 阅读3分钟
原文链接: github.com

JitPack Android Arsenal

参考Kennyc1012/MultiStateView这个这个写的,1.0版本只是在这个上面加了默认布局,以及修正了在设计器中无法预览的问题 2.0是自己写的,主要增加了自定义状态,当然,核心原理还是那样

用于切换不同View的各种状态,默认包含Content,Empty,Fail,Loading 4个状态,并且支持添加其他状态 并且处理了Loading显示时间很短立刻切换到其他状态时看起来好像Loading界面闪了一下

screenshot



    

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



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进行设置

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

要将MultiStateView引入你的项目,需要修改你的build.gradle

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    compile 'com.github.XuDaojie:MultiStateView:v2.2.1'
}

Kennyc1012/MultiStateView android.support.v4.widget.ContentLoadingProgressBar

JitPack Android Arsenal

参考Kennyc1012/MultiStateView这个这个写的,1.0版本只是在这个上面加了默认布局,以及修正了在设计器中无法预览的问题 2.0是自己写的,主要增加了自定义状态,当然,核心原理还是那样

用于切换不同View的各种状态,默认包含Content,Empty,Fail,Loading 4个状态,并且支持添加其他状态 并且处理了Loading显示时间很短立刻切换到其他状态时看起来好像Loading界面闪了一下

screenshot



    

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



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进行设置

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

要将MultiStateView引入你的项目,需要修改你的build.gradle

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    compile 'com.github.XuDaojie:MultiStateView:v2.2.1'
}

Kennyc1012/MultiStateView android.support.v4.widget.ContentLoadingProgressBar

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

www.apache.org/licenses/LI…

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.

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

www.apache.org/licenses/LI…

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.