Giter VIP home page Giter VIP logo

loadinglayout's Introduction

LoadingLayout

方便的切换到加载中,空页面,出错页面和内容页面

效果图

LoadingLayout集成自Framelayout,默认把第一个子view当做内容视图,其他的子view会被忽略

使用如下:

<com.xiaomagouche.loadinglayout.library.LoadingLayout
    android:id="@+id/loading_layout"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">
  <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      >
    <TextView
        android:layout_centerInParent="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is Content View"
        />
  </RelativeLayout>
</com.xiaomagouche.loadinglayout.library.LoadingLayout>

可以通过代码来切换到不同的view

final LoadingLayout loadingLayout = (LoadingLayout) findViewById(R.id.loading_layout);
findViewById(R.id.btn_show_content).setOnClickListener((view) -> loadingLayout.showContent());
findViewById(R.id.btn_show_error).setOnClickListener((view) -> loadingLayout.showError());
findViewById(R.id.btn_show_empty).setOnClickListener((view) -> loadingLayout.showEmpty());
findViewById(R.id.btn_show_loading).setOnClickListener((view) -> loadingLayout.showLoading());

另外,针对errorView和emptyView,提供了两个重新加载的按钮。 需要注意的是,这里的重新加载的按钮的id必须是btn_error_retry或者btn_empty_retry

loadingLayout.setOnRetryClickListener((view) -> loadingLayout.showLoading());

当然,你也可以自己自定义各种视图

<com.xiaomagouche.loadinglayout.library.LoadingLayout
      android:id="@+id/loading_layout"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="1"
      app:emptyView="@layout/custom_empty_view"
      app:loadingView="@layout/custom_loading_view">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
      <TextView
          android:layout_centerInParent="true"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="This is Content View"
          />
    </RelativeLayout>
</com.xiaomagouche.loadinglayout.library.LoadingLayout>

Gradle中使用

推荐使用jitpack

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

dependencies {
    compile 'com.github.lzyzsd:XMFE-TEAM:LoadingLayout:0.1.0'
}

License

MIT

loadinglayout's People

Contributors

uknownothingsnow avatar

Watchers

James Cloos avatar  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.