老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

重慶分公司,新征程啟航

為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)

Android的LayoutInflater

在 實際開發(fā)中LayoutInflater這個類還是非常有用的,它的作用類似于findViewById()。不同點是LayoutInflater是用 來找res/layout/下的xml布局文件,并且實例化;而findViewById()是找xml布局文件下的具體widget控件(如 Button、TextView等)。
具體作用:
1、對于一個沒有被載入或者想要動態(tài)載入的界面,都需要使用LayoutInflater.inflate()來載入;

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

LayoutInflater 是一個抽象類,在文檔中如下聲明:

publicabstractclass LayoutInflater extends Object 



獲得 LayoutInflater 實例的三種方式

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ì)是相同的,從源碼中可以看出:這三種方式最終本質(zhì)是都是調(diào)用的Context.getSystemService()。

下面是一個Demo

公司主營業(yè)務(wù):成都做網(wǎng)站、網(wǎng)站建設(shè)、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)公司是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)公司推出長沙免費做網(wǎng)站回饋大家。

  1. main.xml

  2. encoding="utf-8"?>     

  3. xmlns:android="http://schemas.android.com/apk/res/android"    

  4.     android:orientation="vertical"    

  5.     android:layout_width="fill_parent"    

  6.     android:layout_height="fill_parent"    

  7.     >     

  8.     android:layout_width="fill_parent"      

  9.     android:layout_height="wrap_content"      

  10.     android:text="@string/hello"    

  11.     />     

  12.     android:id="@+id/button"    

  13.     android:layout_width="wrap_content"    

  14.     android:layout_height="wrap_content"    

  15.     android:text="ShowCustomDialog"    

  16.     />     

  17.   

復(fù)制代碼

定義對話框的布局方式custom_dialog.xml

  1. encoding="utf-8"?>     

  2. xmlns:android="http://schemas.android.com/apk/res/android"    

  3.               android:orientation="horizontal"    

  4.               android:layout_width="fill_parent"    

  5.               android:layout_height="fill_parent"    

  6.               android:padding="10dp"    

  7.               >     

  8.    

  9.                android:layout_width="wrap_content"    

  10.                android:layout_height="fill_parent"    

  11.                android:layout_marginRight="10dp"    

  12.                />     

  13.    

  14.               android:layout_width="wrap_content"    

  15.               android:layout_height="fill_parent"    

  16.               android:textColor="#FFF"    

  17.               />     

  18.    

復(fù)制代碼

Activity代碼

  1. package com.android.tutor;  

  2. import android.app.Activity;  

  3. import android.app.AlertDialog;  

  4. import android.content.Context;  

  5. import android.os.Bundle;  

  6. import android.view.LayoutInflater;  

  7. import android.view.View;  

  8. import android.view.View.OnClickListener;  

  9. import android.widget.Button;  

  10. import android.widget.ImageView;  

  11. import android.widget.TextView;  

  12. public class LayoutInflaterDemo extends Activity implements   

  13. OnClickListener {  

  14.       

  15. private Button button;  

  16.     public void onCreate(Bundle savedInstanceState) {  

  17.         super.onCreate(savedInstanceState);  

  18.         setContentView(R.layout.main);  

  19.           

  20.         button = (Button)findViewById(R.id.button);  

  21.         button.setOnClickListener(this);  

  22.     }  

  23. @Override 

  24. public void onClick(View v) {  

  25.     

  26.   showCustomDialog();  

  27. }  

  28.    

  29. public void showCustomDialog()  

  30. {  

  31.   AlertDialog.Builder builder;  

  32.   AlertDialog alertDialog;  

  33.   Context mContext = LayoutInflaterDemo.this;  

  34.     

  35.   //下面?zhèn)z種方法都可以  

  36.   //LayoutInflater inflater = getLayoutInflater();  

  37.   LayoutInflater inflater = (LayoutInflater)   mContext.getSystemService(LAYOUT_INFLATER_SERVICE);  

  38.   View layout = inflater.inflate(R.layout.custom_dialog,null);  //返回值為view

  39.   TextView text = (TextView) layout.findViewById(R.id.text);  

  40.   text.setText("Hello, Welcome to Mr Wei's blog!");  

  41.   ImageView p_w_picpath = (ImageView) layout.findViewById(R.id.p_w_picpath);  

  42.   p_w_picpath.setImageResource(R.drawable.icon);  

  43.   builder = new AlertDialog.Builder(mContext);  

  44.   builder.setView(layout);  

  45.   alertDialog = builder.create();  

  46.   alertDialog.show();  

  47. }  

  48. }   

復(fù)制代碼

運行效果:


Android的LayoutInflater


分享標(biāo)題:Android的LayoutInflater
本文鏈接:http://www.xueling.net.cn/article/jeejsh.html

其他資訊

在線咨詢
服務(wù)熱線
服務(wù)熱線:028-86922220
TOP
主站蜘蛛池模板: 天天看逼 | 日韩毛片一区二区三区 | 精品一区在线视频 | 国产第一区在线 | 亚洲成人网一区 | 国产成人啪精品视频免费网 | 国产九九久久99精品影院 | 中文在线第一页 | 中文字幕网伦射乱中文 | 琪琪午夜成人理论福利片 | 午夜精品久久久久影视 | 老师穿超短包臀裙办公室爆乳 | 欧美精品毛片 | 亚洲精品国产品国语原创 | 日本无码精品一二三四区视频 | 91久久久爱一区二区三区 | 国产精品久久久久久久久久久久午夜片 | 久久精品免费观看 | 60—70sexvideos老少配 | 色蜜桃网| 成人免费视频软件网站 | 国产美女遭强高潮网站观看 | 国产成人欧美一区二区三区一色天 | 亚洲国产欧美自拍 | 怦然心动2在线观看免费高清 | 亚洲精品不卡 | 日韩中文字幕手机在线 | 亚洲一区二区三区蜜桃 | 久久精品国产亚洲AV麻豆~ | 国产无av码在线观看 | 国产一级毛片在线 | 免费无码一级成年片在线观看 | 国产免费区一区二区三视频免费 | 丰满少妇夜夜爽爽高潮水网站 | 护士被两个病人伦奷日出白浆 | 免费小视频在线观看 | 国产在线播放观看 | 日本在线看 | 精品视频在线免费看 | 午夜精品一区二区三区在线视频 | 午夜亚洲国产理论片无码片 |