1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      inflater如何在Android中使用

      這篇文章給大家介紹inflater 如何在Android中使用,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

      網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、微信平臺小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了濟(jì)源免費建站歡迎大家使用!

      1、對于一個沒有被載入或者想要動態(tài)載入的界面,都需要使用LayoutInflater.inflate()來載入;

      2、對于一個已經(jīng)載入的界面,就可以使用Activiyt.findViewById()方法來獲得其中的界面元素。

      文檔中的聲明:

      public abstract class LayoutInflater extends Object

      三種實例化方式:

      1.LayoutInflater inflater = getLayoutInflater(); //調(diào)用Activity的getLayoutInflater()
      2.LayoutInflater localinflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      3. LayoutInflater inflater = LayoutInflater.from(context);

      其實,這三種方式本質(zhì)是相同的,從源碼中可以看出:

      getLayoutInflater():

      Activity 的 getLayoutInflater() 方法是調(diào)用 PhoneWindow 的getLayoutInflater()方法,看一下該源代碼:

       public PhoneWindow(Context context) { 
          super(context); 
          mLayoutInflater = LayoutInflater.from(context); 
      }

      可以看出它其實是調(diào)用 LayoutInflater.from(context)。

      LayoutInflater.from(context):

      public static LayoutInflater from(Context context) {  
        LayoutInflater LayoutInflater =  
            (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
        if (LayoutInflater == null) {  
          throw new AssertionError("LayoutInflater not found.");  
        }  
        return LayoutInflater;  
      }

      可以看出它其實調(diào)用 context.getSystemService()。

      結(jié)論:所以這三種方式最終本質(zhì)是都是調(diào)用的Context.getSystemService()。

      inflate 方法

      通過 sdk 的 api 文檔,可以知道該方法有以下幾種過載形式,返回值均是 View 對象,如下

       public View inflate (int resource, ViewGroup root)
      public View inflate (XmlPullParser parser, ViewGroup root)
      public View inflate (XmlPullParser parser, ViewGroup root, boolean attachToRoot)
      public View inflate (int resource, ViewGroup root, boolean attachToRoot)

      示意代碼:

      LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); 
      View view = inflater.inflate(R.layout.custom, (ViewGroup)findViewById(R.id.test)); 
      //EditText editText = (EditText)findViewById(R.id.content);// error 
      EditText editText = (EditText)view.findViewById(R.id.content); 
      **對于上面代碼,指定了第二個參數(shù) ViewGroup root,當(dāng)然你也可以設(shè)置為 null 值。**

      注意:

      ·inflate 方法與 findViewById 方法不同;

      ·inflater 是用來找 res/layout 下的 xml 布局文件,并且實例化;

      ·findViewById() 是找具體 xml 布局文件中的具體 widget 控件(如:Button、TextView 等)。

      關(guān)于inflater 如何在Android中使用就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。


      網(wǎng)頁名稱:inflater如何在Android中使用
      本文鏈接:http://ef60e0e.cn/article/gegsip.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        昌宁县| 讷河市| 上犹县| 九寨沟县| 永平县| 舞钢市| 沁阳市| 额敏县| 云南省| 昭通市| 河北区| 花莲市| 留坝县| 博湖县| 石渠县| 阿坝| 白银市| 山东| 绥德县| 平顶山市| 云南省| 庆城县| 清水县| 巴林左旗| 海原县| 永昌县| 郯城县| 扎赉特旗| 沾化县| 祁连县| 沅陵县| 建湖县| 秭归县| 佛坪县| 灵璧县| 琼结县| 金溪县| 富民县| 韶关市| 河津市| 遵化市|