Code Monkey home page Code Monkey logo

loadviewhelper's Introduction

LoadViewHelper

布局切换库,加载、空白、错误,可自定义布局类型。

展示

Setup

要使用这个库 minSdkVersion >= 14.

allprojects {
    repositories {
        ...
        jcenter()//一般android studio新建项目都会自动加这行引进这个仓库的
    }
}

dependencies {
    implementation 'com.littleyellow:loadviewhelper:1.0.0'
}

Usage

  • 1.添加全局布局资源,不强制一定添加全局资源,可创建LoadViewHelper时再设置
public static class SettingCallBack implements DefaultSettingCallBack {

        @Override
        public int loadLayoutRes() {
            return R.layout.loading_view;
        }

        @Override
        public int emptyLayoutRes() {
            return R.layout.empty_view;
        }

        @Override
        public int errorLayoutRes() {
            return R.layout.error_view;
        }

        @Override
        public StateChangeListener stateChangeListener() {
            return null;//可返回null,这里可自定义布局显示时的动画
        }
    }

在Application的onCreate()方法里调用下面方法设置全局资源,也可在其他地方设置不过要注意内部类内存泄露问题

LoadViewHelper.DefaultLayoutListener(new SettingCallBack());
  • 2.viewGroup有且只有一个子控件,即内容控件
LoadViewHelper loadViewHelper = LoadViewHelper.newBuilder()
//                .emptyLayoutRes(R.layout.empty_view)
//                .errorLayoutRes(R.layout.error_view)
//                .errorLayoutRes(R.layout.loading_view)
//               .addCustomLayout(LOGIN_LAYOUT,R.layout.login_view)    //这里添加自定义布局,显示时要对应设置对的LOGIN_LAYOUT状态
//               .stateChangeListener(new ShadeStateChangeListener())
                 .build()
                 .attach(viewGroup);

显示内容

loadViewHelper.showContent();

显示加载

loadViewHelper.showLoading();

显示空白

loadViewHelper.showEmpty();

显示错误

loadViewHelper.showError();

显示自定义布局

loadViewHelper.showCustom(int state);

License

Copyright (C) 2019, 小黄
  
   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.

loadviewhelper's People

Contributors

tinyellow avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.