android 界面显示ProgressLayout

项目地址: ProgressLayout
简介:An extension of RelativeLayout that helps show loading, empty and error layout.

An extension of RelativeLayout that helps show loading, empty and error layout.

Screenshot





Download

Add to your module's build.gradle:

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

and:

dependencies {
    compile 'com.github.nguyenhoanglam:ProgressLayout:1.0.0'
}

How to use

  • Use ProgressLayout like RelativeLayout in xml file.

    <?xml version="1.0" encoding="utf-8"?>
    <com.nguyenhoanglam.progresslayout.ProgressLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/progressLayout"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
    
      <android.support.v7.widget.Toolbar
          android:id="@+id/toolbar"
          android:layout_width="match_parent"
          android:layout_height="?attr/actionBarSize"
          android:layout_alignParentTop="true"
          android:background="@color/colorPrimary"
          app:theme="@style/CustomToolbarTheme" />
    
      <TextView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_below="@id/toolbar"
          android:layout_centerInParent="true"
          android:gravity="center"
          android:text="YOUR CONTENT HERE"
          android:textSize="24sp" />
    </com.nguyenhoanglam.progresslayout.ProgressLayout>
    
  • Call methods to show loading, empty or error when needed. ```java @Override protected void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
    
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      toolbar.setTitle("Progress Layout");
    
      ProgressLayout progressLayout = (ProgressLayout) findViewById(R.id.progressLayout);
    
      // Show progress layout and keep main views visible
      // skipIds is a list of view's ids which you want to show with ProgressLayout (in this case is the Toobar)
      List<Integer> skipIds = new ArrayList<>();
      skipIds.add(R.id.toolbar);
    
      progressLayout.showLoading(skipIds);
      progressLayout.showEmpty(ContextCompat.getDrawable(this, R.drawable.ic_empty), "Empty data",skipIds);
      progressLayout.showError(ContextCompat.getDrawable(this, R.drawable.ic_no_connection), "No connection", "RETRY", new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Toast.makeText(MainActivity.this, "Reloading...", Toast.LENGTH_SHORT).show();
          }
      },skipIds);
    
    // Show progress layout, hide all main views
    progressLayout.showLoading();
    progressLayout.showEmpty(ContextCompat.getDrawable(this, R.drawable.ic_empty), "Empty data");
    progressLayout.showError(ContextCompat.getDrawable(this, R.drawable.ic_no_connection), "No connection", "RETRY", new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(MainActivity.this, "Reloading...", Toast.LENGTH_SHORT).show();
        }
    });

}
- Custom ProgressLayout's attributes
```java
<com.nguyenhoanglam.progresslayout.ProgressLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/progressLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:emptyContentTextColor="@color/grey"
    app:emptyContentTextSize="14sp"
    app:emptyImageHeight="200dp"
    app:emptyImageWidth="200dp"
    app:errorButtonTextColor="@color/teal"
    app:errorButtonTextSize="14sp"
    app:errorContentTextColor="@color/grey"
    app:errorContentTextSize="14sp"
    app:errorImageHeight="200dp"
    app:errorImageWidth="200dp"
    app:loadingProgressBarColor="@color/teal"
    app:loadingProgressBarRadius="100dp"
    app:loadingProgressBarSpinWidth="8dp"/>


数据载入状态布局集成allprojects {     repositories {         maven { url "https://jitpack.io" }     } }dependencies {     compile 'com.github.nguyenhoanglam:ProgressLayout:1.0.1' }使用像使用RelativeLayout一样(其实ProgressLayout继承了RelativeLayout):<?xml version="1.0" encoding="utf-8"?> <com.nguyenhoanglam.progresslayout.ProgressLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:id="@ id/progressLayout"     android:layout_width="match_parent"     android:layout_height="match_parent">     <android.support.v7.widget.Toolbar         android:id="@ id/toolbar"         android:layout_width="match_parent"         android:layout_height="?attr/actionBarSize"         android:layout_alignParentTop="true"         android:background="@color/colorPrimary"         app:theme="@style/CustomToolbarTheme" />     <TextView         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_below="@id/toolbar"         android:layout_centerInParent="true"         android:gravity="center"         android:text="YOUR CONTENT HERE"         android:textSize="24sp" /> </com.nguyenhoanglam.progresslayout.ProgressLayout>切换状态progressLayout.showLoading();//???? progressLayout.showEmpty();//???? progressLayout.showError();//????设置监听List<Integer> skipIds = new ArrayList<>(); skipIds.add(R.id.toolbar);         progressLayout.showLoading(skipIds);         progressLayout.showEmpty(ContextCompat.getDrawable(this, R.drawable.ic_empty), "Empty data",skipIds); //        progressLayout.showError(ContextCompat.getDrawable(this, R.drawable.ic_no_connection), "No connection", "RETRY", new View.OnClickListener() { //            @Override //            public void onClick(View view) { //                Toast.makeText(MainActivity.this, "Reloading...", Toast.LENGTH_SHORT).show(); //            } //        },skipIds);           // Show progress layout, hide all main views //        progressLayout.showLoading(); //        progressLayout.showEmpty(ContextCompat.getDrawable(this, R.drawable.ic_empty), "Empty data"); //        progressLayout.showError(ContextCompat.getDrawable(this, R.drawable.ic_no_connection), "No connection", "RETRY", new View.OnClickListener() { //            @Override //            public void onClick(View view) { //                Toast.makeText(MainActivity.this, "Reloading...", Toast.LENGTH_SHORT).show(); //            } //        });skipIds是ProgressLayout中显示的view id列表 
可根据加载情况显示提示信息的载入视图,如,加载失败后提示"加载失败"、"网络连接失败"等等。用一个控件就可以管理整个的加载过程。确实方便了。项目地址:https://github.com/antonkrasov/AndroidProgressLayout 效果图:如何使用将<com.github.androidprogresslayout.ProgressLayout> 作为整个布局的根:<com.github.androidprogresslayout.ProgressLayout         xmlns:android="http://schemas.android.com/apk/res/android"         xmlns:app="http://schemas.android.com/apk/res-auto"         android:id="@ id/progress_layout"         android:layout_width="match_parent"         android:layout_height="match_parent"               >     ...你的页面 </com.github.androidprogresslayout.ProgressLayout>2. 得到ProgressLayoutProgressLayout progressLayout = (ProgressLayout) this.findViewById(R.id.progress_layout);3. 通过progressLayout.showContent()来打开loading,或者你也可以使用属性:app:progress="true"mHandler.postDelayed(new Runnable() {     @Override     public void run() { //progressLayout.showContent();//加载成功,关闭loading progressLayout.showErrorText("加载失败");//加载失败,并显示提示信息     } }, 2000);利用Handler模拟了一个2秒的载入过程。如果载入成功,调用progressLayout.showContent()关闭loading。如果载入失败,调用progressLayout.showErrorText("加载失败")显示失败信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值