1、ViewStub 的基本使用:
(1):布局文件
<ViewStub android:layout_width="match_parent" android:layout_height="0px" android:inflatedId="@id/vs_loading" android:layout="@layout/layout_loading" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toBottomOf="@+id/include" />
android:layout: 为引用的布局文件。
(2):代码调用显示该ViewStub
try { //如果没有被inflate过,使用inflate膨胀 View inflated = mVSLoading.inflate(); AutoUtils.auto(inflated); } catch (Exception e) { //如果使用inflate膨胀报错,使用setVisibility方法显示 mVSLoading.setVisibility(View.VISIBLE); }
2、状态动态切换activity 的基类的实现: