【layout】Android中使用ViewStub来提高UI的加载的性能
来源:互联网 发布:sql server 2005介绍 编辑:程序博客网 时间:2024/06/02 17:57
首先看下API中的ViewStub
布局文件:
demo_viewstub.xml:
根据的文档的说明,ViewStub是一种默认不可见的试图,它没有大小,所以不能被改变,也不能通过某些把viewstub添加到布局当中来,
不过我们可以使用inflate()来吧ViewStub中的试图增加进行,这样可以实现动态的添加试图,不必要每次在onCreate()的时候就加载布局,可以提高我们的性能。
Demo中的使用方法:
1:新建布局文件 设置<ViewStub>节点
2: 在Activity中进行按钮点击 viewStub = (ViewStub) findViewById(R.id.mystub);
3: View view = viewStub.inflate(); 把ViewStub中的View增添进来
下面Demo源代码:
主Activity类:
package com.jiangqq.viewstubdemo; 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 ViewStubActivity extends Activity { private Button btn; private ViewStub viewStub; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btn = (Button) findViewById(R.id.btn); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { viewStub = (ViewStub) findViewById(R.id.mystub); View view = viewStub.inflate(); v.setEnabled(false); } }); } }
布局文件:
main.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="点击确定" /> <ViewStub android:id="@+id/mystub" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout="@layout/demo_viewstub" > </ViewStub> </LinearLayout>
demo_viewstub.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ViewStubDemo_Byjiangqq" /> </LinearLayout>
0 0
- 【layout】Android中使用ViewStub来提高UI的加载的性能
- Android中使用ViewStub来提高UI的加载的性能
- 使用ViewStub来提高加载性能吧!
- Android提高布局加载性能ViewStub的快速实战应用
- Android中使用ViewStub提高布局性能
- ViewStub动态加载布局提高UI加载性能
- Android中如何提高UI的性能
- Android中如何提高UI的性能
- Android中如何提高UI的性能
- Android中如何提高UI的性能
- Android中ViewStub的使用
- Android中ViewStub的使用
- Android使用ViewStub提高布局性能
- Android使用ViewStub提高布局性能
- android--性能提升ViewStub的使用
- Android-优化UI性能(4)-使用ViewStub
- Android开发之UI性能优化(1)-ViewStub的运用
- android UI 优化之<viewstub>实现View的延迟加载
- uva 1347 - Tour(双调欧几里得旅行商问题)
- FIF全称People Finder Interchange Format是一个应用广泛的数据开源的标准协议
- Java中char和int类型的转换问题
- MySql数据类型
- SQL 连接查询语法及使用
- 【layout】Android中使用ViewStub来提高UI的加载的性能
- 软件版本GA,RC,alpha,beta,Build 含义
- 黑马程序员 Java基础之IO流<二>IO流概述及InputStream字节流
- git命令符提交
- 为女神的生日准备惊喜,我开始学习html5游戏开发 -第一天
- Javascript的四种继承方式
- codeforces Round #237(div2) C解题报告
- win8激活及bootMGR is missing问题的解决
- leetCode解题报告之Gas Station