android 按需載入檢視
編寫:allenlsy - 原文:http://developer.android.com/training/improving-layouts/loading-ondemand.html
有時你的 Layout 會用到不怎麼重用的複雜檢視。不管它是列表項 細節,進度顯示器,或是撤銷時的提示資訊,你可以僅在需要的時候載入它們,提高 UI 渲染速度。
定義 ViewStub
ViewStub 是一個輕量的檢視,不需要大小資訊,也不會在被加入的 Layout 中繪製任何東西。每個 ViewStub 只需要設定 android:layout
屬性來指定需要被 inflate 的
Layout 型別。
以下 ViewStub 是一個半透明的進度條覆蓋層。功能上講,它應該只在新的資料項被匯入到應用程式時可見。
<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" />
載入 ViewStub Layout
當你要載入用 ViewStub 宣告的 Layout 時,要麼用 setVisibility(View.VISIBLE)
設定它的可見性,要麼呼叫其 inflate()
方法。
((ViewStub) findViewById(R.id.stub_import)).setVisibility(View.VISIBLE);
// or
View importPanel = ((ViewStub) findViewById(R.id.stub_import)).inflate();
注意:
inflate()
方法會在渲染完成後返回被 inflate 的檢視,所以如果你需要和這個 Layout 互動的話, 你不需要再呼叫findViewById()
去查詢這個元素,。
一旦 ViewStub 可見或是被 inflate 了,ViewStub 元素就不存在了。取而代之的是被 inflate 的 Layout,其 id 是 ViewStub 上的 android:inflatedId
屬性。(ViewStub 的 android:id
屬性僅在 ViewStub 可見以前可用)
注意:ViewStub 的一個缺陷是,它目前不支援使用
<merge/>
標籤的 Layout 。
自:http://hukai.me/android-training-course-in-chinese/performance/improving-layouts/loading-ondemand.html
相關文章
- vue按需載入Vue
- 按需載入原理分析
- 探索Android檢視載入器LayoutInflaterAndroid
- Vue 路由按需載入(路由懶載入)Vue路由
- 按需載入(code spliting)
- VUE如何實現按需載入?Vue
- ant-design按需載入
- Webpack按需載入秒開應用Web
- 腦闊疼的webpack按需載入Web
- 結合載入檢視使用
- react-router4 實現按需載入React
- Gif(2)-載入檢視-波紋
- Webpack的Code Splitting實現按需載入Web
- Vue路由元件按需載入的幾種方法Vue路由元件
- Gif(1)-載入檢視-交替圓效果
- php手動載入檢視檔案PHP
- 高效快速地載入 AngularJS 檢視AngularJS
- antd圖示庫按需載入的外掛實現
- webpack loader—自己寫一個按需載入外掛Web
- 在Webpack中使用Code Splitting實現按需載入Web
- 環形動畫載入檢視AnimatedCircleLoadingView動畫View
- Android顯示框架:Android應用檢視的載體ViewAndroid框架View
- react暴露後,webpack4.19.1實現按需載入antdReactWeb
- 【Vue】路由按需載入(路由懶載入) component: resolve => require([‘../pages/home.vue‘], resolve)Vue路由UI
- UIScrollView載入子檢視偏移64的問題UIView
- 使用webpack4 配置按需載入,減小lodash打包體積Web
- 元件複用那些事兒 - React 實現按需載入輪子元件React
- webpack v3 結合 react-router v4 做 dynamic import — 按需載入(懶載入)WebReactImport
- webpack4下import()模組按需載入,打包按需切割模組,減少包體積,加快首頁請求速度WebImport
- 大規模服務網格效能優化 | Aeraki xDS 按需載入優化
- 嘗試通過AngularJS模組按需載入搭建大型應用(下)AngularJS
- odoo檢視入門學習- tree檢視的使用Odoo
- MySQL入門系列:檢視MySql
- ORACLE物化檢視入門Oracle
- 【vue系列】當 element-ui 按需引入遇到 vue-router 路由懶載入VueUI路由
- pdfjs優化,實現按需載入,節省流量和記憶體JS優化記憶體
- Android元件框架:Android檢視片段FragmentAndroid元件框架Fragment
- 檢視mount掛載情況