一个简单但可以自定义动画的多状态自定义视图

872 阅读1分钟

A custom layout that can easily switch different states(like empty,error,progress,content) with animations.

gif

Add the dependencies to your project:

    dependencies {
        compile 'com.lufficc:stateLayout:0.0.5'
    }

    
      com.lufficc
      stateLayout
      0.0.5
      pom
    

    
      
    

    
    
        
            
            
        
    

        stateLayout.showErrorView(); //switch to error view
        stateLayout.showErrorView(msg); //switch to error view with a message

        stateLayout.showEmptyView();  //switch to empty view
        stateLayout.showEmptyView(msg);  //switch to empty view with a message

        stateLayout.showProgressView();  //switch to progress view
        stateLayout.showProgressView(msg);  //switch to progress view with a message

        stateLayout.showContentView();  //switch to your content view

attr for
app:errorDrawable custom the error drawable
app:emptyDrawable custom the empty drawable
app:progressView custom your own progress view

    setErrorAction(OnClickListener onErrorButtonClickListener); //set a callback called where error view is clicked,
    // you can tetry load data,for example

    etEmptyAction(OnClickListener onEmptyButtonClickListener); // //set a callback called where empty view is clicked

public interface ViewAnimProvider {
    void onHideAndShow(@Nullable View willHide, @NonNull View willShow);
}


stateLayout.setViewSwitchAnimProvider(new FadeViewAnimProvider()); //user it

lufficc.com

Copyright 2016 Copyright 2016 lufficc

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.