APP 中经常有这样的情景,加载页面时不同的状态给用户展示不同的页面,让用户减少等待的焦虑。 为了方便的切换到加载中、空页面、出错页面、重试、内容页面 几种场景 。
##AloadingView集成自Framelayout,使用如下:
<com.jlb.mobile.loadingview.AloadingView
android:id="@+id/loading_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<include layout="@layout/content_view" />
</<com.jlb.mobile.loadingview.AloadingView>
<com.jlb.mobile.loadingview.LoadingLayout
android:id="@+id/loading_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<include layout="@layout/content_view1" /> //显示
<include layout="@layout/content_view2" /> //不显示
<include layout="@layout/content_view3" /> //不显示
<include layout="@layout/content_view4" /> //不显示
</com.jlb.mobile.loadingview.AloadingView>
<com.jlb.mobile.loadingview.AloadingView
android:id="@+id/loading_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<include layout="@layout/ContainView" /> //显示
</com.jlb.mobile.loadingview.AloadingView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
<include layout="@layout/content_view1" />
<include layout="@layout/content_view2" />
<include layout="@layout/content_view3" />
<include layout="@layout/content_view4" />
</LinearLayout>
<com.jlb.mobile.loadingview.AloadingView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/loading_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:contentView="@id/content_view3">
<include layout="@layout/content_view1" /> //不显示
<include layout="@layout/content_view2" /> //不显示
<include layout="@layout/content_view3" /> //显示
<include layout="@layout/content_view4" /> //不显示
</com.jlb.mobile.loadingview.AloadingView>
final AloadingView loadingLayout = (AloadingView) findViewById(R.id.loading_layout);
findViewById(R.id.btn_content).setOnClickListener((view) -> loadingLayout.showContent());
findViewById(R.id.btn_error).setOnClickListener((view) -> loadingLayout.showError());
findViewById(R.id.btn_empty).setOnClickListener((view) -> loadingLayout.showEmpty());
findViewById(R.id.btn_loading).setOnClickListener((view) -> loadingLayout.showLoading());
loadingLayout.setOnRetryClickListener((view) -> loadingLayout.showLoading());
loadingLayout.setOnEmptyClickListener((view) -> loadingLayout.showLoading());
自定义 aloading_view.xml、aloading_error_view.xml、aloading_empty_view.xml,保持文件名和 Button ID 不变即可。
MIT