Skip to content

LianjiaTech/ProgressLayout

Repository files navigation

#ProgressLayout

![Method count](https://img.shields.io/badge/Method count - 62-ff69b4.svg?style=flat) ![Size](https://img.shields.io/badge/Size - 10 KB-ff69b4.svg?style=flat)

GitHub stars GitHub forks GitHub issues

![GitHub license](https://img.shields.io/badge/License - Apache%202-blue.svg?style=flat-square)

介绍

一个轻量的ProgressLayout,能够帮助你实现“加载中”、“无内容”,“网络错误”,“加载失败”等不同场景下的页面切换与展示,并且支持点击页面重试。

用法

首先,在项目根目录下的build.gradle中添加如下代码:

 allprojects {
    repositories {
      ...
      maven { url "https://jitpack.io" }
    }
  }

其次,在module的build.gradle中添加最新版本库的依赖:

 dependencies {
           compile 'com.github.LianjiaTech:ProgressLayout:x.y.z'
  }

可以通过下几种属性来指定不同情况需要展现的layout:

<resources>
  <declare-styleable name="ProgressLayout">
    <!--正在加载-->
    <attr name="loading_layout" format="integer"/>
    <!--无内容-->
    <attr name="none_content" format="integer"/>
    <!--网络错误-->
    <attr name="network_content" format="integer"/>
    <!--加载失败-->
    <attr name="failed_content" format="integer"/>
  </declare-styleable>

  <attr name="progressLayoutDefStyle" format="reference"/>
</resources>

在Xml中设置

<com.lianjiatech.infrastructure.ProgressLayout
      ......
      app:loading_layout="@layout/loading_layout"
      app:none_content="@layout/none_layout"
      app:network_content="@layout/connectionless_layout"
      app:failed_content="@layout/failed_layout"
      >

    <!--Your content layout-->
   ......

  </com.lianjiatech.infrastructure.ProgressLayout>

在Theme中设置

如果不同的Activity需要对应不同的页面,也可以通过在Theme中指定progressLayoutDefStyle的方式来设置需要的Layout:

  <!-- Base application theme. -->
  <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
     ......

    <item name="progressLayoutDefStyle">@style/progressLayoutStyle</item>
  </style>

  <style name="progressLayoutStyle">
    <item name="loading_layout">@layout/loading_layout</item>
    <item name="none_content">@layout/none_layout</item>
    <item name="network_content">@layout/connectionless_layout</item>
    <item name="failed_content">@layout/failed_layout</item>
  </style>

函数使用

通过调用不同的方法,来展示对应的页面,如.showLoading();.showContent()等。或者为“错误页面”添加点击重试事件:

  progressLayout.showNetError(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                /*重试逻辑*/
            }
        });

GIF

Developed By

License

Copyright 2016 LianjiaTech, Inc.

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.