GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - bugyun/LoadLayout: android 加载布局的两种方式: QuickLoadLayout 和 SuperLoadLayout,完美支持 androidx 和 Android 库!!

BranchesTags
Open more actions menu

Latest commit

 

History

37 Commits
37 Commits

Folders and files

NameName
Last commit message
Last commit date
.idea
.idea
 
 
app
app
 
 
factoryloadlayout
factoryloadlayout
 
 
gradle/wrapper
gradle/wrapper
 
 
loadlayoutlib
loadlayoutlib
 
 
quick_load_layout
quick_load_layout
 
 
super_load_layout
super_load_layout
 
 
superloadlayout
superloadlayout
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build.gradle
build.gradle
 
 
gradle.properties
gradle.properties
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
settings.gradle
settings.gradle
 
 

Repository files navigation

LoadLayout

android 加载布局的两种方式

  • QuickLoadLayout
  • SuperLoadLayout

完美支持 androidx 和 Android 库。


QuickLoadLayout

使用方法,在使用的子 build.gradle 中添加配置

implementation 'vip.ruoyun.widget:quick-load-layout:1.0.3'

xml设置

  • loadEmptyLayout : 没有数据显示的界面,对应状态 LoadMode.NO_DATA
  • loadErrorLayout : 网络错误显示的界面,对应状态 LoadMode.ERROR
  • loadLoadingLayout : 加载中的界面,对应状态 LoadMode.LOADING
  • loadNoNetworkLayout : 没有网络显示的界面,对应状态 LoadMode.NO_NETWORK
  • 成功的界面 : LoadMode.SUCCESS
<vip.ruoyun.widget.quick.QuickLoadLayout
    android:id="@+id/mQuickLoadLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:loadEmptyLayout="@layout/quick_layout_load_no_data"
    app:loadErrorLayout="@layout/quick_layout_load_error"
    app:loadLoadingLayout="@layout/quick_layout_load_loading"
    app:loadNoNetworkLayout="@layout/quick_layout_load_no_network">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="我是内容" />
</vip.ruoyun.widget.quick.QuickLoadLayout>

代码设置

可以添加点击事件,重新加载,NO_DATA,ERROR,NO_NETWORK 的布局会响应此事件

mQuickLoadLayout = findViewById(R.id.mQuickLoadLayout);
mQuickLoadLayout.setOnReloadListener(new QuickLoadLayout.OnReloadListener() {
    @Override
    public void onReload() {
        mQuickLoadLayout.setLoadMode(QuickLoadLayout.LoadMode.LOADING);
    }
});

最佳实现

public class QuickLoadLayoutActivity extends AppCompatActivity {

    private Handler handler = new Handler();
    private QuickLoadLayout mQuickLoadLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_quick_load_layout);
        mQuickLoadLayout = findViewById(R.id.mQuickLoadLayout);
        mQuickLoadLayout.setOnReloadListener(new QuickLoadLayout.OnReloadListener() {
            @Override
            public void onReload() {
                mQuickLoadLayout.setLoadMode(QuickLoadLayout.LoadMode.LOADING);
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mQuickLoadLayout.setLoadMode(QuickLoadLayout.LoadMode.SUCCESS);
                    }
                }, 2000);
            }
        });
        mQuickLoadLayout.setLoadMode(QuickLoadLayout.LoadMode.LOADING);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mQuickLoadLayout.setLoadMode(QuickLoadLayout.LoadMode.ERROR);
            }
        }, 2000);
    }
}

SuperLoadLayout

使用方法,在使用的子 build.gradle 中添加配置

implementation 'vip.ruoyun.widget:super-load-layout:1.0.3'

xml

<vip.ruoyun.widget.superlayout.SuperLoadLayout
    android:id="@+id/mSuperLoadLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="我是成功界面" />

</vip.ruoyun.widget.superlayout.SuperLoadLayout>

创建 state ,各种状态创建对应的类

public class SuperCreateLoadBuildHelper {

    public static SuperLoadLayout.Builder create(IFetchData iFetchData) {
        return new SuperLoadLayout.Builder()
                .buildCreateErrorLayout(new ErrorILoadLayoutState(iFetchData))//网络错误
                .buildCreateLoadingLayout(new LoadingLayoutState(iFetchData))//加载中
                .buildCreateNoDataLayout(new NoDataLayoutState(iFetchData))//没有数据
                .buildCreateNoNetworkLayout(new NoNetworkLayoutState(iFetchData))//没有网络
                .build();
    }
}

创建对应的状态,需要实现 ISuperLoadLayoutState 接口,

public class LoadingLayoutState implements ISuperLoadLayoutState {

    //或者通过接口来实现
    private IFetchData iFetchData;

    public LoadingLayoutState(IFetchData iFetchData) {
        this.iFetchData = iFetchData;
    }

    @Override
    public int onCreateLayoutId() {//对应的布局
        return R.layout.layout_load_loading;
    }

    @Override
    public void onCreateView(View view) {
        //在这里进行一些 findviewbyid
        //setOnClick 等操作
    }

    @Override
    public void onShow() {
        //当界面要展示的时候,会回调此方法,比如开始动画
    }

    @Override
    public void onHide() {
        //当界面要展示的时候,会回调此方法,比如结束动画
    }
}

把创建好的 build 传入到 SuperLoadLayout 类中。

mSuperLoadLayout.setBuilder(SuperCreateLoadBuildHelper.create(this));

最佳实现

public interface IFetchData {
    void fetchData();//加载数据的接口
}

public class SuperLoadLayoutActivity extends BaseActivity {

    private SuperLoadLayout mSuperLoadLayout;
    private Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_super_load_layout);
        mSuperLoadLayout = findViewById(R.id.mSuperLoadLayout);
        mSuperLoadLayout.setBuilder(SuperCreateLoadBuildHelper.create(this));
        mSuperLoadLayout.setLoadMode(SuperLoadLayout.LoadMode.LOADING);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mSuperLoadLayout.setLoadMode(QuickLoadLayout.LoadMode.NO_NETWORK);
            }
        }, 2000);
    }

    @Override
    public void fetchData() {
        mSuperLoadLayout.setLoadMode(SuperLoadLayout.LoadMode.LOADING);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mSuperLoadLayout.setLoadMode(SuperLoadLayout.LoadMode.SUCCESS);
            }
        }, 3000);
    }
}

About

android 加载布局的两种方式: QuickLoadLayout 和 SuperLoadLayout,完美支持 androidx 和 Android 库!!

Topics

androidandroid-libraryandroid-uilayoutloadlayout

Resources

Readme
Apache-2.0 license
Activity

Stars

4 stars

Watchers

2 watching

Forks

1 fork
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.