Android简单布局优化3

来源:互联网 发布:数据库原理及应用 编辑:程序博客网 时间:2024/05/22 11:45


通过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>
0 0
原创粉丝点击