zoukankan      html  css  js  c++  java
  • [Android]Android布局优化之 ViewStub

    转载请标注:转载于http://www.cnblogs.com/Liuyt-61/p/6602926.html 

    ----------------------------------------------------------------

    >使用ViewStub惰性加载

    作用:ViewStub标签同include标签一样可以用来引入一个外部布局,不同的是,ViewStub引入的布局默认不会扩张,既不会占用显示,也不会占用位置,从而在解析layout时节省cpu和内存。

    common_text.xml
    
    <?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" >
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="隐藏内容" />
    
    </LinearLayout>
    
    ------------------------------------------------
    main.xml
    
    <?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" >
    
        <include layout="@layout/common_title" />
    
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
    
            <TextView
                android:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="正文内容"
                android:textSize="16sp" />
    
            <include layout="@layout/common_progress" />
        </FrameLayout>
    
        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="显示隐藏内容" />
    
        <ViewStub
            android:id="@+id/viewStub"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout="@layout/common_text" />
    
    </LinearLayout>
    --------------------------------------
    MainActivity.java
    
    package com.Liuyt.s03_e22_include;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.ViewStub;
    import android.widget.Button;
    
    public class MainActivity extends Activity {
    
        private Button btn;
        private ViewStub viewStub;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            btn = (Button) findViewById(R.id.button);
            viewStub = (ViewStub) findViewById(R.id.viewStub);
            btn.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    viewStub.inflate();
                }
            });
        }
    }
  • 相关阅读:
    加州大学Santa Barbara量化课程
    专利分析与申请(2):SILK 专利的特点
    两种可分级语音编码器的量化器
    芬兰赫尔辛基工业大学DirAC工程:Directional audio coding
    SILK 的 Delay Decision 和 Dither
    Fraunhofer 研究院
    ICASSP 论文发表相关问题
    SILK 学习总结之位分配与低码率编码
    今天测试VOIP软件结果
    国内部分音频语音相关研究企业(实时更新)
  • 原文地址:https://www.cnblogs.com/Liuyt-61/p/6602926.html
Copyright © 2011-2022 走看看