通过ViewStub延迟加载(何时需要何时加载)我们需要的元素,可以避免这些元素在加载布局时就占据资源,造成空间浪费。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="48dp">
<!-- 借助ViewStub延迟加载进度条 -->
<ViewStub
android:id="@+id/vStubId"
android:inflatedId="@+id/progressBar1"
android:layout="@layout/progress_layout_01"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!-- 立刻加载(页面初始化时就会构建并加载此对象)
<include layout="@layout/progress_layout_01"/>
-->
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="down"
android:onClick="onClick"/>
</LinearLayout>