Improving Layout Performance(三)
Loading Views On Demand
有时你的布局可能需要一些复杂却又很少被用到的视图。无论他们是item详情、进度指示器,或撤销的消息,你都可以在需要时加载这些视图,来减少内存使用量并加快渲染速度。
Define a ViewStub
ViewStub是一个没有尺寸大小并且不会在布局中嵌套或渲染任何东西的轻量级的视图。因此在视图层次展现或隐藏它的代价非常小。每一个ViewStub仅仅需要包含android:layout属性来展现指定的布局。
以下ViewStub是一个半透明的进度条。他只有在新items被导入到应用中时才是可见的。
<ViewStub
android:id="@+id/stub_import"
android:inflatedId="@+id/panel_import"
android:layout="@layout/progress_overlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
Load the ViewStub Layout
当你想要载入在ViewStub中定义的布局的时候,可以calling setVisibility(View.VISIBLE) or call inflate().
((ViewStub) findViewById(R.id.stub_import)).setVisibility(View.VISIBLE);
// or
View importPanel = ((ViewStub) findViewById(R.id.stub_import)).inflate();
注意:inflate()方法在视图渲染完毕后便直接展现该已渲染的视图View。因此如果你需要和布局交互的话,不需要再调用findViewById()方法
一旦一个ViewStub是可见的或渲染完毕,该元素便不再是视图层次的一部分。它被已渲染的布局替换,并且该布局的根视图的ID是在ViewStub中被android:inflatedId属性指定的ID。(在中被android:id指定的ID只有在这个ViewStub布局是可见/渲染完毕才是有效的。) 注意:ViewStub的一个缺点是,目前它在要渲染的布局中并不支持<merge/>标签
相关推荐
awesome-android-performance This is a list of awesome Android tutorials, videos and tools for performance optimization View Google Official Videos Double Layout Taxation Android Performance Patterns...
Good-Habits-for-Great-Coding-Improving-Programming-Skills-with-Examples-in-Python.pdf
Priority Job Queue is an implementation of a Job Queue specifically written for Android to easily schedule jobs (tasks) that run in the background, improving UX and application stability.
Today’s resource-intensive applications running on Intel® multi-core processor-based platforms are driving the need not only for greater networking bandwidth, but also for more efficient processing ...
ChatMessagesAdapter for Android QuickBlox simple to use UI library for showing quickblox chat messages inside android application. Features Ready-to-go QBChatMessage view adapter with a set of view ...
IEEE Guide for Improving the Lightning Performance of Electric Power Overhead Distribution Lines
用基于模板的方法改善Web服务安全性能 Improving WS-Security Performance with a Template-Based Approach
持续集成 jolt大奖图书 提高软件质量 降低风险
How to improving Android Bootup Time. Android boot sequence. Measuring bootup time. Problem areas. Ideas for improvements.
Sharing Spark RDD states between different Spark applications for improving performance. Processing events & streaming data, integrate Apache Ignite with other frameworks like Storm, Camel, etc. ...
IEEE Std 1243-1997 Guide for Improving the Lightning Performance of Transmission Lines
Improve your coding skills and learn how to write readable code. Rather than teach basic programming, this book presumes that readers understand the fundamentals, and offers time-honed best practices ...
2020-自校正网络20cvpr-SCNet-Improving Convolutional Networks with Self-Calibrated Convolutions1
921164-MB51-Improving the runtime using database 提升MB51/MMBE等事务的查询性能 包含note 和 安装文件
藏经阁-Improving Python and Spark Performance and Interoperability
Improving routing performance when several routing protocols are used sequentially in a WSN
The investigation produced detailed measurements in order to profile the application and help on improving the performance. Code analysis shows that the current IPOP version suffers from ...
Optimizing Java_Practical Techniques for Improving JVM Application Performance-O’Reilly(2018) How do you define performance? Most developers, when asked about the performance of their application, ...
Radically reducing development time and improving development experience. Cloudopt Next absorbed the ideas of Spring Boot,JFinal,Resty,Vertx and other excellent projects, and not only had a very ...
https://engineering.instagram.com/improving-comment-rendering-on-android-a77d5db3d82e http://ragnraok.github.io/textview-pre-render-research.html Features 1.Faster than Android TextView 2.More ...