Android布局加載之LayoutInflater示例詳解-創(chuàng)新互聯(lián)

前言

創(chuàng)新互聯(lián)是一家專注于網(wǎng)站建設、網(wǎng)站設計與策劃設計,靈山網(wǎng)站建設哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設10年,網(wǎng)設計領(lǐng)域的專業(yè)建站公司;建站業(yè)務涵蓋:靈山等地區(qū)。靈山做網(wǎng)站價格咨詢:028-86922220

Activity 在界面創(chuàng)建時需要將 XML 布局文件中的內(nèi)容加載進來,正如我們在 ListView 或者 RecyclerView 中需要將 Item 的布局加載進來一樣,都是使用 LayoutInflater 來進行操作的。

LayoutInflater 實例的獲取有多種方式,但最終是通過(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)來得到的,也就是說加載布局的 LayoutInflater 是來自于系統(tǒng)服務的。

由于 Android 系統(tǒng)源碼中關(guān)于 Content 部分采用的是裝飾模式,Context 的具體功能都是由 ContextImpl 來實現(xiàn)的。通過在 ContextImpl 中找到getSystemService的代碼,一路跟進,得知最后返回的實例是PhoneLayoutInflater。

  registerService(Context.LAYOUT_INFLATER_SERVICE, LayoutInflater.class,
    new CachedServiceFetcher<LayoutInflater>() {
   @Override
   public LayoutInflater createService(ContextImpl ctx) {
    return new PhoneLayoutInflater(ctx.getOuterContext());
   }});

分享標題:Android布局加載之LayoutInflater示例詳解-創(chuàng)新互聯(lián)
轉(zhuǎn)載來于:http://muchs.cn/article38/dhgpsp.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣、網(wǎng)站設計公司、電子商務、網(wǎng)站設計、營銷型網(wǎng)站建設App設計

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設計