最简单的状态切换布局

功能简介

  • 正在加载数据
  • 数据加载失败
  • 数据加载为空
  • 网络加载失败
  • 重试点击事件
  • 支持自定义布局

效果图展示

效果图

最简单的使用方式

1.Add it in your root build.gradle at the end of repositories:

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

2.Add the dependency

    dependencies {
            implementation 'com.github.pengMaster:MultipleLayout:1.0.0'
    }

3.在布局中添加


    <king.bird.multipleview.MultipleLayout
        android:id="@+id/mMultipleLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!--任意内容-->
        <TextView
            android:id="@+id/mTvContent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="@string/content" />

    </king.bird.multipleview.MultipleLayout>


 注意: MultipleLayout 可做为没有标题栏的最外层布局,内部可包裹任何内容

4.代码中使用

        //重试点击事件
        mMultipleLayout.setOnRetryClickListener {
            //模拟网络请求
            Toast.makeText(this@MainActivity,"正在加载。。",Toast.LENGTH_SHORT).show()
        }
        //数据为空
        mMultipleLayout.showEmpty()
        //加载失败
        mMultipleLayout.showError()
        //正在加载
        mMultipleLayout.showLoading()
        //网络加载失败
        mMultipleLayout.showNoNetwork()
        //显示内容
        mMultipleLayout.showContent()


扩展功能

1.自定义状态布局

    <king.bird.multipleview.MultipleLayout
        android:id="@+id/multipleStatusView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        <!--自定义布局-->
        app:emptyView="@layout/layout_empty_view"
        app:errorView="@layout/layout_error_view"
        app:loadingView="@layout/layout_loading_view"
        app:noNetworkView="@layout/layout_network_view">

    </king.bird.multipleview.MultipleLayout>

2.代码引入布局

        //数据为空
        showEmpty(int layoutId, ViewGroup.LayoutParams layoutParams)
        showEmpty(View view, ViewGroup.LayoutParams layoutParams)
        //加载失败
        showError(int layoutId, ViewGroup.LayoutParams layoutParams)
        showError(View view, ViewGroup.LayoutParams layoutParams)
        //正在加载
        showLoading(int layoutId, ViewGroup.LayoutParams layoutParams)
        showLoading(View view, ViewGroup.LayoutParams layoutParams)
        //网络加载失败
        void showNoNetwork(int layoutId, ViewGroup.LayoutParams layoutParams)
        showNoNetwork(View view, ViewGroup.LayoutParams layoutParams)

3.扩展

后续添加各种弹框

参与贡献

  1. Fork 本项目
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

github地址

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,366评论 25 709
  • 用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你...
    hw1212阅读 14,472评论 2 59
  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,040评论 3 119
  • 很容易就被感动,样子就是静静的默默地流泪。对有些人有些情的歉意和悲悯!
    莎莎33阅读 1,020评论 0 0
  • 我总喜欢将一个人想象的很神圣,很无私,很专一,就像你。 你是我杜撰出来的,你不会像别人一样,有许多的暧...
    船长和他的卷毛狗阅读 3,964评论 0 0