一区二区三区电影_国产伦精品一区二区三区视频免费_亚洲欧美国产精品va在线观看_国产精品一二三四

聯(lián)系我們 - 廣告服務(wù) - 聯(lián)系電話:
您的當(dāng)前位置: > 關(guān)注 > > 正文

Android中LayoutParams是什么?Android中LayoutParams總結(jié)和用法

來源:CSDN 時(shí)間:2022-12-08 15:16:05

日積月累第三周第四天。又是忙碌的一天,昨天看了兩集老羅的Android 視頻教程,感覺講的很基礎(chǔ)。繼續(xù)堅(jiān)持一天一集視頻。今天上班接觸了一下Android 的LayoutParams今天加以整理和梳理。

先查看一下API 中是如何介紹的,以搜索太多了。就挑一個(gè)ViewGroup.LayoutParams 看一下吧。

http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html


(資料圖片)

LayoutParams are used by views to tell their parents how they want to be laid out. See ViewGroup Layout Attributesfor a list of all child view attributes that this class supports.

The base LayoutParams class just describes how big the view wants to be for both width and height. For each dimension, it can specify one of:

FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the view wants to be as big as its parent (minus padding)WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content (plus padding)an exact number There are subclasses of LayoutParams for different subclasses of ViewGroup. For example, AbsoluteLayout has its own subclass of LayoutParams which adds an X and Y value.

Developer Guides

For more information about creating user interface layouts, read the XML Layouts developer guide.

我在這里看了一篇?jiǎng)e人博客對(duì)于LayoutParams的解釋,我覺的很到位,所以就繼續(xù)拿來主義。

其實(shí)這個(gè)LayoutParams類是用于child view(子視圖) 向 parent view(父視圖)傳達(dá)自己的意愿的一個(gè)東西(孩子想變成什么樣向其父親說明)其實(shí)子視圖父視圖可以簡(jiǎn)單理解成 一個(gè)LinearLayout 和 這個(gè)LinearLayout里邊一個(gè) TextView 的關(guān)系 TextView 就算LinearLayout的子視圖 child view 。需要注意的是LayoutParams只是ViewGroup的一個(gè)內(nèi)部類這里邊這個(gè)也就是ViewGroup里邊這個(gè)LayoutParams類是 base class 基類實(shí)際上每個(gè)不同的ViewGroup都有自己的LayoutParams子類 比如LinearLayout 也有自己的 LayoutParams 大家打開源碼看幾眼就知道了 myeclipse 怎么查看源碼 請(qǐng)看http://byandby.iteye.com/blog/814277 下邊來個(gè)例子

Java代碼 :       //創(chuàng)建一個(gè)線性布局          private LinearLayout mLayout;             mLayout = (LinearLayout) findViewById(R.id.layout);            //現(xiàn)在我要往mLayout里邊添加一個(gè)TextView         //你可能會(huì)想直接在布局文件里邊配置不就O 了 那是 但是這里為了說明問題我們用代碼實(shí)現(xiàn)         TextView textView = new TextView(Activity01.this);                 textView.setText("Text View " );              //這里請(qǐng)不要困惑這里是設(shè)置 這個(gè)textView的布局 FILL_PARENT WRAP_CONTENT 和在xml文件里邊設(shè)置是一樣的如       //在xml里邊怎么配置高寬大家都會(huì)的。     //第一個(gè)參數(shù)為寬的設(shè)置,第二個(gè)參數(shù)為高的設(shè)置。              LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(                         LinearLayout.LayoutParams.FILL_PARENT,                         LinearLayout.LayoutParams.WRAP_CONTENT                 );                 //調(diào)用addView()方法增加一個(gè)TextView到線性布局中              mLayout.addView(textView, p);                //比較簡(jiǎn)單的一個(gè)例子

如果還不能理解下邊在來一段直白的說明: LayoutParams繼承于Android.View.ViewGroup.LayoutParams. LayoutParams相當(dāng)于一個(gè)Layout的信息包,它封裝了Layout的位置、高、寬等信息。假設(shè)在屏幕上一塊區(qū)域是由一個(gè)Layout占領(lǐng)的,如果將一個(gè)View添加到一個(gè)Layout中,最好告訴Layout用戶期望的布局方式,也就是將一個(gè)認(rèn)可的layoutParams傳遞進(jìn)去。 可以這樣去形容LayoutParams,在象棋的棋盤上,每個(gè)棋子都占據(jù)一個(gè)位置,也就是每個(gè)棋子都有一個(gè)位置的信息,如這個(gè)棋子在4行4列,這里的“4行4列”就是棋子的LayoutParams。 但LayoutParams類也只是簡(jiǎn)單的描述了寬高,寬和高都可以設(shè)置成三種值: 1,一個(gè)確定的值; 2,F(xiàn)ILL_PARENT,即填滿(和父容器一樣大小); 3,WRAP_CONTENT,即包裹住組件就好。

關(guān)于setLayoutParams報(bào)錯(cuò)

在繼承BaseAdapter的時(shí)候,用getView返回View的時(shí)候,用代碼控制布局,需要用到View.setLayoutParams,但是報(bào)錯(cuò)了,報(bào)的是類型轉(zhuǎn)換錯(cuò)誤,經(jīng)過研究,發(fā)現(xiàn),這里不能使用ViewGroup.LayoutParams而必須使用對(duì)應(yīng)父View的LayoutParams類型。如:某View被LinearLayout包含,則該View的setLayoutParams參數(shù)類型必須是LinearLayout.LayoutParams。原因在于LinearLayout(或其他繼承自ViewGroup的layout,如:RelativeLayout)在進(jìn)行遞歸布局的時(shí)候,LinearLayout會(huì)獲取子View的LayoutParams,并強(qiáng)制轉(zhuǎn)換成LinearLayout.LayoutParams,如

1 LinearLayout.LayoutParams lp  =  (LinearLayout.LayoutParams) child.getLayoutParams();

或者是如下定義:

1 LayoutParams lp  =  (LayoutParams) child.getLayoutParams();

以轉(zhuǎn)換成內(nèi)部類型LinearLayout.LayoutParams。

自己測(cè)試運(yùn)行的時(shí)候報(bào)空指針,原因?yàn)閏hild.getLayoutParams();這里沒有獲得到子控件所在的布局,查看代碼發(fā)現(xiàn)parent.addView(child);應(yīng)該寫在上面,之后child才能getLayoutParams();

點(diǎn)擊PopupWindow 外部區(qū)域消失 //view 是自定義的點(diǎn)擊PopupWindow 樣式 pop = new PopupWindow(view, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);                 pop.setBackgroundDrawable(new BitmapDrawable());                 pop.setOutsideTouchable(true); pop = new PopupWindow(view, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);                 pop.setBackgroundDrawable(new BitmapDrawable());                 pop.setOutsideTouchable(true); 上面兩句位置不能顛倒,不然無效!(經(jīng)本機(jī)測(cè)試 不知道別人如何)必須設(shè)置backgroundDrawable()

WindowManager.LayoutParams 是 WindowManager 接口的嵌套類;繼承于 ViewGroup.LayoutParams 。          它的內(nèi)容十分豐富。其實(shí)WindowManager.java的主要內(nèi)容就是由這個(gè)類定義構(gòu)成。下面來分析一下這個(gè)類:          定義          public static class WindowManager.LayoutParams extends ViewGroup.LayoutParams implements Parcelable          繼承關(guān)系         java.lang.Object         android.view.ViewGroup.LayoutParams         android.view.WindowManager.LayoutParams         繼承來的屬性與常量         從ViewManager.LayoutParams 繼承來的屬性:         android:layout_height         Specifies the basic height of the view.         android:layout_width         Specifies the basic width of the view.         從ViewManager.LayoutParams繼承的常量:         FILL_PARENT         WRAP_CONTENT         MATCH_PARENT         兩個(gè)變量:         width         height         屬性及可用的常量定義        1. public int x;        如果忽略gravity屬性,那么它表示窗口的絕對(duì)X位置。        什么是gravity屬性呢?簡(jiǎn)單地說,就是窗口如何停靠。        當(dāng)設(shè)置了 Gravity.LEFT 或 Gravity.RIGHT 之后,x值就表示到特定邊的距離。        2. public int y;        如果忽略gravity屬性,那么它表示窗口的絕對(duì)Y位置。        當(dāng)設(shè)置了 Gravity.TOP 或 Gravity.BOTTOM 之后,y值就表示到特定邊的距離。        3. public float horizontalWeight;        public float verticalWeight;        在縱/橫向上,為關(guān)聯(lián)的view預(yù)留了多少擴(kuò)展空間(像素)。如果是0,那么此view不能被拉伸。        其他情況下,擴(kuò)展空間(像素)將被widget所均分。        4. public int type;         窗口類型。         有3種主要類型:         Applicationwindows:         取值在 FIRST_APPLICATION_WINDOW 和 LAST_APPLICATION_WINDOW 之間。         是通常的、頂層的應(yīng)用程序窗口。必須將 token 設(shè)置成 activity 的 token 。        Sub_windows:         取值在 FIRST_SUB_WINDOW 和 LAST_SUB_WINDOW 之間。         與頂層窗口相關(guān)聯(lián),token 必須設(shè)置為它所附著的宿主窗口的 token。         Systemwindows:         取值在 FIRST_SYSTEM_WINDOW 和 LAST_SYSTEM_WINDOW 之間。         用于特定的系統(tǒng)功能。它不能用于應(yīng)用程序,使用時(shí)需要特殊權(quán)限。         下面定義了 type 的取值:

//應(yīng)用程序窗口。 public static final int FIRST_APPLICATION_WINDOW = 1;  //所有程序窗口的“基地”窗口,其他應(yīng)用程序窗口都顯示在它上面。  public static final int TYPE_BASE_APPLICATION =1; //普通應(yīng)用功能程序窗口。token必須設(shè)置為Activity的token,以指出該窗口屬誰。 public static final int TYPE_APPLICATION = 2; //用于應(yīng)用程序啟動(dòng)時(shí)所顯示的窗口。應(yīng)用本身不要使用這種類型。 //它用于讓系統(tǒng)顯示些信息,直到應(yīng)用程序可以開啟自己的窗口。  public static final int TYPE_APPLICATION_STARTING = 3;  //應(yīng)用程序窗口結(jié)束。 public static final int LAST_APPLICATION_WINDOW = 99; //子窗口。子窗口的Z序和坐標(biāo)空間都依賴于他們的宿主窗口。 public static final int FIRST_SUB_WINDOW = 1000; //面板窗口,顯示于宿主窗口上層。 public static final int TYPE_APPLICATION_PANEL = FIRST_SUB_WINDOW; //媒體窗口,例如視頻。顯示于宿主窗口下層。 public static final int TYPE_APPLICATION_MEDIA = FIRST_SUB_WINDOW+1; //應(yīng)用程序窗口的子面板。顯示于所有面板窗口的上層。(GUI的一般規(guī)律,越“子”越靠上) public static final int TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW +2; //對(duì)話框。類似于面板窗口,繪制類似于頂層窗口,而不是宿主的子窗口。 public static final int TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW +3; //媒體信息。顯示在媒體層和程序窗口之間,需要實(shí)現(xiàn)透明(半透明)效果。(例如顯示字幕) public static final int TYPE_APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW +4; //子窗口結(jié)束。( End of types of sub-windows ) public static final int LAST_SUB_WINDOW = 1999; //系統(tǒng)窗口。非應(yīng)用程序創(chuàng)建。 public static final int FIRST_SYSTEM_WINDOW = 2000; //狀態(tài)欄。只能有一個(gè)狀態(tài)欄;它位于屏幕頂端,其他窗口都位于它下方。 public static final int TYPE_STATUS_BAR = FIRST_SYSTEM_WINDOW; //搜索欄。只能有一個(gè)搜索欄;它位于屏幕上方。 public static final int TYPE_SEARCH_BAR = FIRST_SYSTEM_WINDOW+1; //電話窗口。它用于電話交互(特別是呼入)。它置于所有應(yīng)用程序之上,狀態(tài)欄之下。 public static final int TYPE_PHONE = FIRST_SYSTEM_WINDOW+2; //系統(tǒng)提示。它總是出現(xiàn)在應(yīng)用程序窗口之上。 public static final int TYPE_SYSTEM_ALERT = FIRST_SYSTEM_WINDOW +3; //鎖屏窗口。 public static final int TYPE_KEYGUARD = FIRST_SYSTEM_WINDOW +4; //信息窗口。用于顯示toast。 public static final int TYPE_TOAST = FIRST_SYSTEM_WINDOW +5; //系統(tǒng)頂層窗口。顯示在其他一切內(nèi)容之上。此窗口不能獲得輸入焦點(diǎn),否則影響鎖屏。 public static final int TYPE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW +6; //電話優(yōu)先,當(dāng)鎖屏?xí)r顯示。此窗口不能獲得輸入焦點(diǎn),否則影響鎖屏。 public static final int TYPE_PRIORITY_PHONE = FIRST_SYSTEM_WINDOW +7; //系統(tǒng)對(duì)話框。(例如音量調(diào)節(jié)框)。 public static final int TYPE_SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW +8; //鎖屏?xí)r顯示的對(duì)話框。 public static final int TYPE_KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW +9; //系統(tǒng)內(nèi)部錯(cuò)誤提示,顯示于所有內(nèi)容之上。 public static final int TYPE_SYSTEM_ERROR = FIRST_SYSTEM_WINDOW +10; //內(nèi)部輸入法窗口,顯示于普通UI之上。應(yīng)用程序可重新布局以免被此窗口覆蓋。 public static final int TYPE_INPUT_METHOD = FIRST_SYSTEM_WINDOW +11; //內(nèi)部輸入法對(duì)話框,顯示于當(dāng)前輸入法窗口之上。 public static final int TYPE_INPUT_METHOD_DIALOG= FIRST_SYSTEM_WINDOW +12; //墻紙窗口。 public static final int TYPE_WALLPAPER = FIRST_SYSTEM_WINDOW +13; //狀態(tài)欄的滑動(dòng)面板。 public static final int TYPE_STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW +14; //系統(tǒng)窗口結(jié)束。 public static final int LAST_SYSTEM_WINDOW = 2999;  5. public int memoryType;        指出窗口所使用的內(nèi)存緩沖類型。默認(rèn)為 NORMAL 。        下面定義了 memoryType 的取值:        窗口緩沖位于主內(nèi)存。        public static final int MEMORY_TYPE_NORMAL = 0;        窗口緩沖位于可以被DMA訪問,或者硬件加速的內(nèi)存區(qū)域。        public static final int MEMORY_TYPE_HARDWARE = 1;        窗口緩沖位于可被圖形加速器訪問的區(qū)域。        public static final int MEMORY_TYPE_GPU = 2;        窗口緩沖不擁有自己的緩沖區(qū),不能被鎖定。緩沖區(qū)由本地方法提供。        public static final int MEMORY_TYPE_PUSH_BUFFERS = 3;        6.  public int flags;        行為選項(xiàng)/旗標(biāo),默認(rèn)為 none .下面定義了 flags 的取值:

//窗口之后的內(nèi)容變暗。 public static final int FLAG_DIM_BEHIND = 0x00000002; //窗口之后的內(nèi)容變模糊。 public static final int FLAG_BLUR_BEHIND = 0x00000004;  不許獲得焦點(diǎn)。 不能獲得按鍵輸入焦點(diǎn),所以不能向它發(fā)送按鍵或按鈕事件。那些時(shí)間將發(fā)送給它后面的可以獲得焦點(diǎn)的窗口。此選項(xiàng)還會(huì)設(shè)置FLAG_NOT_TOUCH_MODAL選項(xiàng)。設(shè)置此選項(xiàng),意味著窗口不能與軟輸入法進(jìn)行交互,所以它的Z序獨(dú)立于任何活動(dòng)的輸入法(換句話說,它可以全屏顯示,如果需要的話,可覆蓋輸入法窗口)。要修改這一行為,可參考FLAG_ALT_FOCUSALBE_IM選項(xiàng)。 public static final int FLAG_NOT_FOCUSABLE = 0x00000008; //不接受觸摸屏事件。 public static final int FLAG_NOT_TOUCHABLE = 0x00000010; 當(dāng)窗口可以獲得焦點(diǎn)(沒有設(shè)置 FLAG_NOT_FOCUSALBE 選項(xiàng))時(shí),仍然將窗口范圍之外的點(diǎn)設(shè)備事件(鼠標(biāo)、觸摸屏)發(fā)送給后面的窗口處理。否則它將獨(dú)占所有的點(diǎn)設(shè)備事件,而不管它們是不是發(fā)生在窗口范圍內(nèi)。 public static final int FLAG_NOT_TOUCH_MODAL = 0x00000020; 如果設(shè)置了這個(gè)標(biāo)志,當(dāng)設(shè)備休眠時(shí),點(diǎn)擊觸摸屏,設(shè)備將收到這個(gè)第一觸摸事件。 通常第一觸摸事件被系統(tǒng)所消耗,用戶不會(huì)看到他們點(diǎn)擊屏幕有什么反應(yīng)。 public static final int FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040; 當(dāng)此窗口為用戶可見時(shí),保持設(shè)備常開,并保持亮度不變。 public static final int FLAG_KEEP_SCREEN_ON = 0x00000080; 窗口占滿整個(gè)屏幕,忽略周圍的裝飾邊框(例如狀態(tài)欄)。此窗口需考慮到裝飾邊框的內(nèi)容。 public static final int FLAG_LAYOUT_IN_SCREEN =0x00000100; 允許窗口擴(kuò)展到屏幕之外。 public static final int FLAG_LAYOUT_NO_LIMITS =0x00000200; 窗口顯示時(shí),隱藏所有的屏幕裝飾(例如狀態(tài)條)。使窗口占用整個(gè)顯示區(qū)域。 public static final int FLAG_FULLSCREEN = 0x00000400; 此選項(xiàng)將覆蓋FLAG_FULLSCREEN選項(xiàng),并強(qiáng)制屏幕裝飾(如狀態(tài)條)彈出。 public static final int FLAG_FORCE_NOT_FULLSCREEN =0x00000800; 抖動(dòng)。指 對(duì)半透明的顯示方法。又稱“點(diǎn)透”。圖形處理較差的設(shè)備往往用“點(diǎn)透”替代Alpha混合。 public static final int FLAG_DITHER = 0x00001000; //不允許屏幕截圖。 public static final int FLAG_SECURE = 0x00002000; //一種特殊模式,布局參數(shù)用于指示顯示比例。 public static final int FLAG_SCALED = 0x00004000; //當(dāng)屏幕有可能貼著臉時(shí),這一選項(xiàng)可防止面頰對(duì)屏幕造成誤操作。 public static final int FLAG_IGNORE_CHEEK_PRESSES = 0x00008000; //當(dāng)請(qǐng)求布局時(shí),你的窗口可能出現(xiàn)在狀態(tài)欄的上面或下面,從而造成遮擋。當(dāng)設(shè)置這一選項(xiàng)后,窗口管理器將確保窗口內(nèi)容不會(huì)被裝飾條(狀態(tài)欄)蓋住。 public static final int FLAG_LAYOUT_INSET_DECOR = 0x00010000; //反轉(zhuǎn)FLAG_NOT_FOCUSABLE選項(xiàng)。 //如果同時(shí)設(shè)置了FLAG_NOT_FOCUSABLE選項(xiàng)和本選項(xiàng),窗口將能夠與輸入法交互,允許輸入法窗口覆蓋; 如果FLAG_NOT_FOCUSABLE沒有設(shè)置而設(shè)置了本選項(xiàng),窗口不能與輸入法交互,可以覆蓋輸入法窗口。 public static final int FLAG_ALT_FOCUSABLE_IM = 0x00020000; //如果你設(shè)置了FLAG_NOT_TOUCH_MODAL,那么當(dāng)觸屏事件發(fā)生在窗口之外事,可以通過設(shè)置此標(biāo)志接收到一個(gè)MotionEvent.ACTION_OUTSIDE事件。注意,你不會(huì)收到完整的down/move/up事件,只有第一次down事件時(shí)可以收到ACTION_OUTSIDE。 public static final int FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000; //當(dāng)屏幕鎖定時(shí),窗口可以被看到。這使得應(yīng)用程序窗口優(yōu)先于鎖屏界面。可配合FLAG_KEEP_SCREEN_ON選項(xiàng)點(diǎn)亮屏幕并直接顯示在鎖屏界面之前。可使用FLAG_DISMISS_KEYGUARD選項(xiàng)直接解除非加鎖的鎖屏狀態(tài)。此選項(xiàng)只用于最頂層的全屏幕窗口。 public static final int FLAG_SHOW_WHEN_LOCKED = 0x00080000; //請(qǐng)求系統(tǒng)墻紙顯示在你的窗口后面。窗口必須是半透明的。 public static final int FLAG_SHOW_WALLPAPER = 0x00100000; //窗口一旦顯示出來,系統(tǒng)將點(diǎn)亮屏幕,正如用戶喚醒設(shè)備那樣。 public static final int FLAG_TURN_SCREEN_ON = 0x00200000; //解除鎖屏。只有鎖屏界面不是加密的才能解鎖。如果鎖屏界面是加密的,那么用戶解鎖之后才能看到此窗口,除非設(shè)置了FLAG_SHOW_WHEN_LOCKED選項(xiàng)。 public static final int FLAG_DISMISS_KEYGUARD = 0x00400000; //鎖屏界面淡出時(shí),繼續(xù)運(yùn)行它的動(dòng)畫。 public static final int FLAG_KEEP_SURFACE_WHILE_ANIMATING =0x10000000; //以原始尺寸顯示窗口。用于在兼容模式下運(yùn)行程序。 public static final int FLAG_COMPATIBLE_WINDOW = 0x20000000; //用于系統(tǒng)對(duì)話框。設(shè)置此選項(xiàng)的窗口將無條件獲得焦點(diǎn)。 public static final int FLAG_SYSTEM_ERROR = 0x40000000;       7. public int softInputMode;        軟輸入法模式選項(xiàng):以下選項(xiàng)與 softInputMode 有關(guān):

//軟輸入?yún)^(qū)域是否可見。 public static final int SOFT_INPUT_MASK_STATE = 0x0f; //未指定狀態(tài)。 public static final int SOFT_INPUT_STATE_UNSPECIFIED = 0; //不要修改軟輸入法區(qū)域的狀態(tài)。 public static final int SOFT_INPUT_STATE_UNCHANGED = 1; //隱藏輸入法區(qū)域(當(dāng)用戶進(jìn)入窗口時(shí))。 public static final int SOFT_INPUT_STATE_HIDDEN = 2; //當(dāng)窗口獲得焦點(diǎn)時(shí),隱藏輸入法區(qū)域。 public static final int SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3; //顯示輸入法區(qū)域(當(dāng)用戶進(jìn)入窗口時(shí))。 public static final int SOFT_INPUT_STATE_VISIBLE = 4; //當(dāng)窗口獲得焦點(diǎn)時(shí),顯示輸入法區(qū)域。 public static final int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5; //窗口應(yīng)當(dāng)主動(dòng)調(diào)整,以適應(yīng)軟輸入窗口。 public static final int SOFT_INPUT_MASK_ADJUST = 0xf0; //未指定狀態(tài),系統(tǒng)將根據(jù)窗口內(nèi)容嘗試選擇一個(gè)輸入法樣式。 public static final int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00; //當(dāng)輸入法顯示時(shí),允許窗口重新計(jì)算尺寸,使內(nèi)容不被輸入法所覆蓋。 //不可與SOFT_INPUT_ADJUSP_PAN混合使用,如果兩個(gè)都沒有設(shè)置,系統(tǒng)將根據(jù)窗口內(nèi)容自動(dòng)設(shè)置一個(gè)選項(xiàng)。 public static final int SOFT_INPUT_ADJUST_RESIZE = 0x10; //輸入法顯示時(shí)平移窗口。它不需要處理尺寸變化,框架能夠移動(dòng)窗口以確保輸入焦點(diǎn)可見。 //不可與SOFT_INPUT_ADJUST_RESIZE混合使用;如果兩個(gè)都沒設(shè)置,系統(tǒng)將根據(jù)窗口內(nèi)容自動(dòng)設(shè)置一個(gè)選項(xiàng)。 public static final int SOFT_INPUT_ADJUST_PAN = 0x20; //當(dāng)用戶轉(zhuǎn)至此窗口時(shí),由系統(tǒng)自動(dòng)設(shè)置,所以你不要設(shè)置它。 //當(dāng)窗口顯示之后該標(biāo)志自動(dòng)清除。 public static final int SOFT_INPUT_IS_FORWARD_NAVIGATION = 0x100;   8. public int gravity;        gravity 屬性。什么是gravity屬性呢?簡(jiǎn)單地說,就是窗口如何停靠。        9. public float horizontalMargin;        水平邊距,容器與widget之間的距離,占容器寬度的百分率。        10. public float verticalMargin;        縱向邊距。        11. public int format;        期望的位圖格式。默認(rèn)為不透明。參考android.graphics.PixelFormat。        12. public int windowAnimations;        窗口所使用的動(dòng)畫設(shè)置。它必須是一個(gè)系統(tǒng)資源而不是應(yīng)用程序資源,因?yàn)榇翱诠芾砥鞑荒茉L問應(yīng)用程序。        13. public float alpha = 1.0f;        整個(gè)窗口的半透明值,1.0表示不透明,0.0表示全透明。        14. public float dimAmount = 1.0f;        當(dāng)FLAG_DIM_BEHIND設(shè)置后生效。該變量指示后面的窗口變暗的程度。        1.0表示完全不透明,0.0表示沒有變暗。        15. public float screenBrightness = -1.0f;        用來覆蓋用戶設(shè)置的屏幕亮度。表示應(yīng)用用戶設(shè)置的屏幕亮度。        從0到1調(diào)整亮度從暗到最亮發(fā)生變化。        16. public IBinder token = null;        窗口的標(biāo)示符。( Identifier for this window. This will usually be filled in for you. )        17. public String packageName = null;        此窗口所在的包名。        18. public int screenOrientation =ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;        屏幕方向,參見android.content.pm.ActivityInfo#screenOrientation。        19. 在兼容模式下,備份/恢復(fù)參數(shù)所使用的內(nèi)部緩沖區(qū)。        public int[] mCompatibilityParamsBackup = null;

layoutanimation,顧名思義,是用來設(shè)置給viewgroup類型的animation,是子view來執(zhí)行的。可以是

[java]view plain copy android:layoutAnimation="@anim/popinlayout"    也可以是javacode的 [java]view plain copy viewgroup.setLayoutAnimation(layoutnaimationcontroller);

和Animation類似,Layout Animation也支持Animation Listener,具體的就不多說了。layoutanimation會(huì)在View Group第一次進(jìn)行布局的時(shí)候執(zhí)行一次。

具體來說,layoutanimation支持三個(gè)參數(shù),

1,anim就不多說了,

2,animationOrder,這個(gè)是說子view按照什么順序來執(zhí)行anim,可以使normal(正常,0-n),reverse(反序,n-0),random。一般不要太亂的還是normal

3,delay,用于延遲的每個(gè)子view的動(dòng)畫開始動(dòng)畫持續(xù)時(shí)間的浮點(diǎn)數(shù)。越大間隔越長(zhǎng)。0.3或者30%的字樣。

另外,LayoutAnimationController包含一個(gè)內(nèi)部類,LayoutAnimationController.AnimationParameters,這個(gè)類主要包括了count和index兩個(gè)參數(shù)。這些參數(shù)用于計(jì)算每個(gè)單獨(dú)的視圖動(dòng)畫的開始時(shí)間。

ViewGroup.LayoutParams這個(gè)類大家都一定很熟悉的,主要是height和width。其中還有一個(gè)字段,就是LayoutAnimationController.AnimationParameters,Used to animate layouts。

layoutanimation一般可以用在listview等adapterview中,顯得比較炫一些。

比如:

[html]view plain copy

listview中還有一個(gè)viewgroup的屬性,android:persistentDrawingCache

Defines the persistence of the drawing cache. The drawing cache might be enabled by a ViewGroup for all its children in specific situations (for instance during a scrolling.) This property lets you persist the cache in memory after its initial usage. Persisting the cache consumes more memory but may prevent frequent garbage collection is the cache is created over and over again. By default the persistence is set to scrolling.

定義繪圖的高速緩存的持久性。 繪圖緩存可能由一個(gè) ViewGroup 在特定情況下為其所有的子類啟用,例如在一個(gè)滾動(dòng)的過程中。 此屬性可以保留在內(nèi)存中的緩存后其初始的使用。 堅(jiān)持緩存會(huì)消耗更多的內(nèi)存,但可能會(huì)阻止頻繁的垃圾回收是反復(fù)創(chuàng)建緩存。 默認(rèn)情況下持續(xù)存在設(shè)置為滾動(dòng)。

其屬性值只有以下幾種:

ConstantValueDescription none 0x0  The drawing cache is not persisted after use. animation 0x1  The drawing cache is persisted after a layout animation. scrolling 0x2The drawing cache is persisted after a scroll. all 0x3  The drawing cache is always persisted.

一般默認(rèn)的有scrolling屬性,我們?cè)谟衛(wèi)ayoutAnimation動(dòng)畫的時(shí)候添加上animation屬性會(huì)更流通些。

LayoutAnimationController用于為一個(gè)layout里面的控件,或者是一個(gè)ViewGroup里面的控件設(shè)置動(dòng)畫效果,可以在XML文件中設(shè)置,亦可以在Java代碼中設(shè)置。

一種直接在XML文件中設(shè)置

1.  在res/anim文件夾下新建一個(gè)XML文件,名為list_anim_layout.xml,

[java]view plain copy

android:delay  子類動(dòng)畫時(shí)間間隔 (延遲)   70% 也可以是一個(gè)浮點(diǎn)數(shù) 如“1.2”等

android:animationOrder="random"   子類的顯示方式 random表示隨機(jī)

android:animationOrder 的取值有

normal0默認(rèn)

reverse1倒序

random2隨機(jī)

android:animation="@anim/slide_right" 表示孩子顯示時(shí)的具體動(dòng)畫是什么

說明:其中delay的單位為秒;animation為設(shè)置動(dòng)畫的文件。animationOrder為進(jìn)入方式

2.  在res/anim文件夾下新建一個(gè)XML文件,名為slide_right,即上面用到的文件。

[html]view plain copy

顯示的效果為L(zhǎng)istView第一次出現(xiàn)的時(shí)候?yàn)?item隨機(jī)出現(xiàn) 每個(gè)Item都是從左不可見(-100%p)的區(qū)域向右滑動(dòng)到顯示的地方

3.  在主布局文件中為控件添加如下配置:

android:layoutAnimation="@anim/list_anim_layout",即第一步的布局文件。

第二種設(shè)置方法:在Java代碼中設(shè)置

1. 同上;

2. 同上;

4.  在Acitivty中添加如下代碼:

//通過加載XML動(dòng)畫設(shè)置文件來創(chuàng)建一個(gè)Animation對(duì)象;

Animation animation=AnimationUtils.loadAnimation(this, R.anim.list_anim);

//得到一個(gè)LayoutAnimationController對(duì)象;

LayoutAnimationController lac=newLayoutAnimationController(animation);

//設(shè)置控件顯示的順序;

lac.setOrder(LayoutAnimationController.ORDER_REVERSE);

//設(shè)置控件顯示間隔時(shí)間;

lac.setDelay(1);

//為L(zhǎng)istView設(shè)置LayoutAnimationController屬性;

datalist.setLayoutAnimation(lac);

有兩種用法,我的通常寫在代碼中,像下面這樣:

Java代碼   /**       * Layout動(dòng)畫       *        * @return       */       protected LayoutAnimationController getAnimationController() {           int duration=300;           AnimationSet set = new AnimationSet(true);              Animation animation = new AlphaAnimation(0.0f, 1.0f);           animation.setDuration(duration);           set.addAnimation(animation);              animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,                   Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,                   -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);           animation.setDuration(duration);           set.addAnimation(animation);              LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);           controller.setOrder(LayoutAnimationController.ORDER_NORMAL);           return controller;       }   應(yīng)用的時(shí)候只需這樣:  Java代碼   listView = (ListView) findViewById(R.id.listView);   listView.setLayoutAnimation(getAnimationController());   adapter = new ListViewAdapter(stores);   listView.setAdapter(adapter);   這樣一個(gè)簡(jiǎn)單的LayoutAnimation就完成了。  別看到這里就以為文章就完了,以上都是些小玩意。呵呵,還有更厲害的!  你想設(shè)置更炫的動(dòng)畫嗎?LayoutAnimation通常是Item一個(gè)一個(gè)的出現(xiàn),有某種規(guī)律的。想讓每個(gè)Item都有自己的動(dòng)畫嗎?那就繼續(xù)看下去。  Java代碼   .......   private int duration=1000;           private Animation push_left_in,push_right_in;           private Animation slide_top_to_bottom,slide_bottom_to_top;           public ListViewAdapter(ArrayListlist) {               this.list = list;               push_left_in=AnimationUtils.loadAnimation(context, R.anim.push_left_in);               push_right_in=AnimationUtils.loadAnimation(context, R.anim.push_right_in);               slide_top_to_bottom=AnimationUtils.loadAnimation(context, R.anim.slide_top_to_bottom);               slide_bottom_to_top=AnimationUtils.loadAnimation(context, R.anim.slide_bottom_to_top);           }   ........      @Override           public View getView(int position, View convertView, ViewGroup parent) {               // TODO Auto-generated method stub               ViewHodler hodler;               if (convertView == null) {                   hodler = new ViewHodler();                   convertView = LayoutInflater.from(context).inflate(                           R.layout.simple_item_7_for_main, null);                   ........                                                         convertView.setTag(hodler);                                      if (position % 2 == 0) {                       push_left_in.setDuration(duration);                       convertView.setAnimation(push_left_in);                   } else {                       push_right_in.setDuration(duration);                       convertView.setAnimation(push_right_in);                   }                                      /*if(position==0){slide_bottom_to_top.setDuration(duration);                      convertView.setAnimation(slide_bottom_to_top);                  }                  else{slide_top_to_bottom.setDuration(duration);                      convertView.setAnimation(slide_top_to_bottom);                  }*/                                  }else{                   hodler = (ViewHodler) convertView.getTag();               }   ........                                             return convertView;           }   看見上面的動(dòng)畫設(shè)置了嗎?將動(dòng)畫寫在getView()中,這樣可以設(shè)置很多不同的動(dòng)畫。其實(shí)這不屬于LayoutAnimation的范疇了。  你可以試一下,如果設(shè)計(jì)好的話,可以有比LayoutAnimation更酷的效果。  我這里只試了兩種效果。  下面是我的動(dòng)畫文件,共四個(gè):  第一種效果:item分別從左右兩側(cè)滑入效果。  push_left_in.xml  Xml代碼   push_right_in.xml  Xml代碼   第2種效果:第一個(gè)item從下往上滑入,其他Item從上往下滑入效果,這個(gè)效果如果單個(gè)Item比較高(height)的話效果非常酷(卡牛的老版本好像用的就是這種效果)。  slide_bottom_to_top.xml  Xml代碼   slide_top_to_bottom.xml  Xml代碼   另外一篇:  這個(gè)不是我寫的。  GridView的item從上下左右飛入   Java代碼   import java.util.Random;   import android.app.Activity;   import android.content.Context;   import android.os.Bundle;   import android.view.LayoutInflater;   import android.view.View;   import android.view.View.OnClickListener;   import android.view.ViewGroup;   import android.view.animation.Animation;   import android.view.animation.TranslateAnimation;   import android.widget.BaseAdapter;   import android.widget.Button;   import android.widget.GridView;   import android.widget.ImageView;   public class ZdemoActivity extends Activity {        private GridView gv;    private Button btn;    private TranslateAnimation taLeft, taRight, taTop, taBlow;    private int[] imgList = new int[15];    private MyAdapter mAdapter;    private LayoutInflater mInflater;    @Override    public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.main);     this.InitView();     this.InitAnima();     this.InitData();    }    private void InitAnima() {     // TODO Auto-generated method stub     taLeft = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 1.0f,       Animation.RELATIVE_TO_PARENT, 0.0f,       Animation.RELATIVE_TO_PARENT, 0.0f,       Animation.RELATIVE_TO_PARENT, 0.0f);     taRight = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -1.0f,       Animation.RELATIVE_TO_PARENT, 0.0f,       Animation.RELATIVE_TO_PARENT, 0.0f,       Animation.RELATIVE_TO_PARENT, 0.0f);     taTop = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,       Animation.RELATIVE_TO_PARENT, 0.0f,       Animation.RELATIVE_TO_PARENT, 1.0f,       Animation.RELATIVE_TO_PARENT, 0.0f);     taBlow = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,       Animation.RELATIVE_TO_PARENT, 0.0f,       Animation.RELATIVE_TO_PARENT, -1.0f,       Animation.RELATIVE_TO_PARENT, 0.0f);     taLeft.setDuration(1000);     taRight.setDuration(1000);     taTop.setDuration(1000);     taBlow.setDuration(1000);    }    private void InitData() {     // TODO Auto-generated method stub     for (int i = 0; i < 15; i++) {      imgList[i] = R.drawable.ic_launcher;     }     mAdapter = new MyAdapter();     gv.setAdapter(mAdapter);    }    private void InitView() {     // TODO Auto-generated method stub     gv = (GridView) findViewById(R.id.gridView1);     btn = (Button) findViewById(R.id.button1);     btn.setOnClickListener(new OnClickListener() {      @Override      public void onClick(View v) {       // TODO Auto-generated method stub       mAdapter = null;       mAdapter = new MyAdapter();       gv.setAdapter(mAdapter);       mAdapter.notifyDataSetChanged();      }     });     mInflater = (LayoutInflater) this       .getSystemService(Context.LAYOUT_INFLATER_SERVICE);    }    private class MyAdapter extends BaseAdapter {     @Override     public int getCount() {      // TODO Auto-generated method stub      return imgList.length;     }     @Override     public Object getItem(int position) {      // TODO Auto-generated method stub      return imgList[position];     }     @Override     public long getItemId(int position) {      // TODO Auto-generated method stub      return position;     }     @Override     public View getView(int position, View convertView, ViewGroup parent) {      // TODO Auto-generated method stub      ViewHolder holder = null;      if (convertView == null) {       convertView = mInflater.inflate(R.layout.item, null);       holder = new ViewHolder();       holder.image = (ImageView) convertView         .findViewById(R.id.imageView1);       convertView.setTag(holder);      } else {       holder = (ViewHolder) convertView.getTag();      }      int imgID = imgList[position];      holder.image.setImageResource(imgID);      Random ran = new Random();      int rand = ran.nextInt(4);      switch (rand) {      case 0:       convertView.startAnimation(taLeft);       break;      case 1:       convertView.startAnimation(taRight);       break;      case 2:       convertView.startAnimation(taTop);       break;      case 3:       convertView.startAnimation(taBlow);       break;      }      return convertView;     }     class ViewHolder {      public ImageView image;     }    }   }  一、            ViewGroup1.1         概述  定義  public abstract class ViewGroup extends View implements ViewParent, ViewManager  所在的包  import android.view.ViewGroup;  子類信息  View  |___ ViewGroup         |___ AdapterView|      |___ AbsListView         |      |      |___ GridView         |      |      |___ ListView         |      |             |___ ExpandableListView         |      |___ AbsSpinner         |             |___ Gallery         |             |___ Spinner         |___ FrameLayout         |      |___ DatePicker         |      |___ TimePicker         |      |___ MediaController         |      |___ ScrollView         |      |___ TabHost         |      |___ ViewAnimator         |             |___ ViewFlipper         |             |___ ViewSwitcher         |                    |___ ImageSwitcher         |                    |___ TextSwitcher         |___ LinearLayout         |      |___ RadioGroup         |      |___ TabWidget         |      |___ TableLayout         |      |___ TableRow         |      |___ ZoomControls         |___ RelativeLayout         |      |___ DialerFilter         |      |___ TwoLineListItem         |___ AbsoluteLayout                |___ WebView  ViewGroup繼承View,是一組view的集合,通過addView()來添加child view,removeView()、removeAllViews()等刪除child view。addView()加入的view存為數(shù)組,初始化數(shù)組大小為12,超過大小時(shí)每次增加12,每一個(gè)index對(duì)應(yīng)一個(gè)view,可以通過getChildAt()、indexOfChild()來獲取view和index,getChildCount()獲取總child數(shù)。  內(nèi)部類LayoutParams來管理ViewGroup的所占區(qū)域大小。  FILL_PARENT:填充滿parent的寬或高  WRAP_CONTENT:內(nèi)容的實(shí)際大小加邊距  offsetChildrenTopAndBottom()、setPadding()來設(shè)置邊距。  1.2         部分方法  void addView(View child)  void addView(View child, int index)  void addView(View child, int width, int height)  void addView(View child, LayoutParams params)  void addView(View child, int index, LayoutParams params)  void removeView(View view)  void removeViewAt(int index)  void removeViews(int start, int count)  void removeAllViews()  void removeViewInLayout(View view)  void removeViewsInLayout(int start, int count)  void removeAllViewsInLayout()  增加刪除child view  void offsetChildrenTopAndBottom(int offset)  設(shè)置垂直方向頂部和底部的偏移,單位象素  int getChildCount()  int indexOfChild(View child)  View getChildAt(int index)  void setDescendantFocusability(int focusability)  int getDescendantFocusability()  ViewGroup.FOCUS_BEFORE_DESCENDANTS  先于子孫獲得focus  ViewGroup.FOCUS_AFTER_DESCENDANTS  子孫都不需要focus時(shí)viewgroup才獲得  ViewGroup.FOCUS_BLOCK_DESCENDANTS  void setClipChildren(boolean clipChildren)  void setClipToPadding(boolean clipToPadding)  true:滾動(dòng)時(shí)child不可以繪制到padding區(qū)域,即剪裁掉  false:滾動(dòng)時(shí)child可以繪制到padding區(qū)域  void setOnHierarchyChangeListener(OnHierarchyChangeListener listener)  設(shè)置child有add或remove時(shí)觸發(fā)的監(jiān)聽器  void startLayoutAnimation()  運(yùn)行動(dòng)畫  void scheduleLayoutAnimation()  設(shè)置動(dòng)畫狀態(tài),刷新時(shí)運(yùn)行動(dòng)畫  void setLayoutAnimation(LayoutAnimationController controller)  LayoutAnimationController getLayoutAnimation()  設(shè)置布局動(dòng)畫,在child第一次布局時(shí)運(yùn)行動(dòng)畫  void setLayoutAnimationListener(Animation.AnimationListener animationListener)  Animation.AnimationListener getLayoutAnimationListener()  設(shè)置動(dòng)畫播放開始、結(jié)束、重播時(shí)觸發(fā)的監(jiān)聽器  boolean isAnimationCacheEnabled()  void setAnimationCacheEnabled(boolean enabled)  boolean isAlwaysDrawnWithCacheEnabled()  void setAlwaysDrawnWithCacheEnabled(boolean always)  int getPersistentDrawingCache()  void setPersistentDrawingCache(int drawingCacheToKeep)  1.3         ViewGroup.LayoutParams  public static class LayoutParams  ViewGroup.LayoutParams  |___ ViewGroup.MarginLayoutParams  |      |___ FrameLayout.LayoutParams  |      |___ LinearLayout.LayoutParams  |      |      |___ RadioGroup.LayoutParams  |      |      |___ TableLayout.LayoutParams  |      |      |___ TableRow.LayoutParams  |      |___ RelativeLayout.LayoutParams  |___ AbsoluteLayout.LayoutParams  |___ AbsListView.LayoutParams  |___ Gallery.LayoutParams  |___ WindowManager.LayoutParams  public int width;     //指定view的寬高  public int height;  public LayoutAnimationController.AnimationParameters layoutAnimationParameters;  ViewGroup.LayoutParams.FILL_PARENT  ViewGroup.LayoutParams.WRAP_CONTENT  public LayoutParams(Context c, AttributeSet attrs)  public LayoutParams(int width, int height)  public LayoutParams(LayoutParams source)  LayoutParams()  1.4         ViewGroup. MarginLayoutParams  public static class MarginLayoutParams extends ViewGroup.LayoutParams  public int leftMargin;     //在ViewGroup.LayoutParams基礎(chǔ)上增加4個(gè)方向邊距  public int topMargin;  public int rightMargin;  public int bottomMargin;  public MarginLayoutParams(Context c, AttributeSet attrs)  public MarginLayoutParams(int width, int height)  public MarginLayoutParams(MarginLayoutParams source)  public MarginLayoutParams(LayoutParams source)  public void setMargins(int left, int top, int right, int bottom)          Margin        Padding、大小為設(shè)置的width, height,背景繪制的區(qū)域        實(shí)體大小  通過ViewGroup.LayoutParams設(shè)置width,height  View.setLayoutParams(ViewGroup.LayoutParams params);  通過ViewGroup.MarginLayoutParams設(shè)置margin  ViewGroup.MarginLayoutParams.setMargins(int left, int top, int right, int bottom);  ViewGroup.MarginLayoutParams.leftMargin  通過View. setPadding(int left, int top, int right, int bottom); 設(shè)置padding  白色區(qū)域大小:    width+ leftMargin+ rightMargin                              height+ topMargin+ bottomMargin  橙色區(qū)域大小:    width                              height  綠色區(qū)域大小:    width- leftPadding- rightPadding                              height- topPadding- bottomPadding  二、            AdapterView2.1         概述  定義  public abstract class AdapterViewextends ViewGroup  包路徑  import android.widget.AdapterView;  子類信息  View  |___ ViewGroup         |___ AdapterView|___ AbsListView                |      |___ GridView                |      |___ ListView                |             |___ ExpandableListView                |___ AbsSpinner                       |___ Gallery                       |___ Spinner  AdapterView繼承ViewGroup,但AdapterView的child view由Adapter決定,不能通過addView()來添加。  setAdapter()來設(shè)置Adapter,getAdapter()獲取。  2.2         部分方法  void addView(View child)  void addView(View child, int index)  void addView(View child, LayoutParams params)  void addView(View child, int index, LayoutParams params)  void removeView(View child)  void removeViewAt(int index)  void removeAllViews()  不支持添加刪除view,使用則拋出UnsupportedOperationException異常  void setOnClickListener(OnClickListener l)  不支持,拋出異常RuntimeException  abstract T getAdapter()  abstract void setAdapter(T adapter)  設(shè)置child的數(shù)據(jù)和view  int getCount()  int getPositionForView(View view)  long getItemIdAtPosition(int position)  Object getItemAtPosition(int position)  返回Object不一定就是一個(gè)item的view,跟getAdapter().getItem(position)等效  要想獲得view應(yīng)getAdapter().getView(position, convertView, parent)  abstract View getSelectedView()  int getSelectedItemPosition()  long getSelectedItemId()  Object getSelectedItem()  abstract void setSelection(int position)  int getFirstVisiblePosition()  屏幕上可見的第一項(xiàng)的position,部分可見也算  int getLastVisiblePosition()  屏幕上可見的最后一項(xiàng)的position,部分可見也算  void setFocusable(boolean focusable)  void setFocusableInTouchMode(boolean focusable)  void setOnItemClickListener(OnItemClickListener listener)  final OnItemClickListener getOnItemClickListener()  設(shè)置item點(diǎn)擊監(jiān)聽器  boolean performItemClick(View view, int position, long id)  調(diào)用item點(diǎn)擊監(jiān)聽器設(shè)置的回調(diào)函數(shù)  void setOnItemLongClickListener(OnItemLongClickListener listener)  final OnItemLongClickListener getOnItemLongClickListener()  設(shè)置item長(zhǎng)按監(jiān)聽器  void setOnItemSelectedListener(OnItemSelectedListener listener)  final OnItemSelectedListener getOnItemSelectedListener()  設(shè)置item被選擇時(shí)觸發(fā)的監(jiān)聽器  public void setTextFilterEnabled(boolean textFilterEnabled)  public boolean isTextFilterEnabled()  開啟或關(guān)閉過濾窗口,開啟時(shí),鍵盤輸入顯示在屏幕下方一半透明黑色區(qū)域,根據(jù)輸入過濾掉不包含輸入文字的項(xiàng) 二、            Adapter3.1         概述  定義  public interface Adapter  包路徑  import android.widget.Adapter;  SpinnerAdapter  ListAdapter  HeaderViewListAdapter  BaseAdapter  WrapperListAdapter  CursorAdapter  ArrayAdapterSimpleAdapter  Adapter  ResourceCursorAdapter  SimpleCursorAdapter  黑色文字為接口紅色文字為類斜體字為抽象類  子類信息  Adapter是AdapterView和數(shù)據(jù)間的橋梁,提供訪問每項(xiàng)數(shù)據(jù)的接口,并為每項(xiàng)創(chuàng)建一個(gè)view。  3.2         部分方法  void unregisterDataSetObserver(DataSetObserver observer);  void registerDataSetObserver(DataSetObserver observer)  注冊(cè)一個(gè)observer,當(dāng)該Adapter對(duì)象的數(shù)據(jù)變化時(shí)調(diào)用。  int getCount()  Object getItem(int position)  long getItemId(int position)       boolean hasStableIds()  item的id是否穩(wěn)定。穩(wěn)定則數(shù)據(jù)變化時(shí)item 的id不變  View getView(int position, View convertView, ViewGroup parent)  返回顯示position項(xiàng)數(shù)據(jù)的view,可以手動(dòng)創(chuàng)建一個(gè)view也可以通過xml layout文件創(chuàng)建。  position          第position項(xiàng)  convertView   可以為null,送入一個(gè)view,如果這個(gè)view不能轉(zhuǎn)換為需要顯示的view則創(chuàng)建一個(gè)新的view  parent            返回的view加入parent的ViewGroup  int getViewTypeCount()  getView()返回view的種數(shù),如果都返回同一類的view則getViewTypeCount()為1  int getItemViewType(int position)  獲得position項(xiàng)view的類型,可以的返回值有0到getViewTypeCount() – 1和IGNORE_ITEM_VIEW_TYPE  boolean isEmpty()  是否包含有數(shù)據(jù)  ListAdapter增加  boolean isEnabled(int position)  public boolean areAllItemsEnabled()  返回false表示item不可選,不可點(diǎn)擊  SpinnerAdapter增加  public View getDropDownView(int position, View convertView, ViewGroup parent)  position項(xiàng)下拉菜單的view  3.3         ArrayAdapter  class ArrayAdapterextends BaseAdapter implements Filterable  ArrayAdapter(Context context, int textViewResourceId)  ArrayAdapter(Context context, int textViewResourceId, T[] objects)  ArrayAdapter(Context context, int textViewResourceId, Listobjects)  ArrayAdapter(Context context, int resource, int textViewResourceId)  ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects)  ArrayAdapter(Context context, int resource, int textViewResourceId, Listobjects)  context  textViewResourceId  沒有resource參數(shù)時(shí):含有TextView 的layout文件資源ID,創(chuàng)建view時(shí)使用;  有resource參數(shù)時(shí):layout文件中TextView的ID  resource  loyout文件資源ID  objects  ListView顯示的對(duì)象  SDK自帶的textViewResourceId對(duì)應(yīng)的xml文件在cupcake\frameworks\base\core\res\res\layout  android.R.layout.simple_list_item_1  TextView  android.R.layout.simple_list_item_2  含有兩個(gè)TextView的TwoLineListItem  android.R.layout. simple_expandable_list_item_1  TextView  android.R.layout. simple_expandable_list_item_2  含有兩個(gè)TextView的TwoLineListItem  android.R.layout. simple_list_item_single_choice  CheckedTextView  android.R.layout. simple_list_item_multiple_choice  CheckedTextView  android.R.layout. simple_list_item_checked  CheckedTextView  void add(T object)  void insert(T object, int index)  void remove(T object)  void clear()  void notifyDataSetChanged()  void setNotifyOnChange(boolean notifyOnChange)  列表發(fā)生改變時(shí)是否自動(dòng)調(diào)用notifyDataSetChanged(),設(shè)為false則需手動(dòng)調(diào)用  Context getContext()  void setDropDownViewResource(int resource)  設(shè)置創(chuàng)建下拉菜單view需要的layout資源文件  static ArrayAdaptercreateFromResource(Context context,              int textArrayResId, int textViewResId)  Filter getFilter()  3.4         SimpleAdapter  public class SimpleAdapter extends BaseAdapter implements Filterable  public SimpleAdapter(Context context, List> data,              int resource, String[] from, int[] to)  context  data  resource  Layout文件id  from  data中Map的key  to  生成itemView的id, to[]數(shù)組大小不能超過from []的大小  public void setDropDownViewResource(int resource)  設(shè)置創(chuàng)建下拉菜單view需要的layout資源文件  public ViewBinder getViewBinder()  public void setViewBinder(ViewBinder viewBinder)  public static interface ViewBinder {  boolean setViewValue(View view, Object data, String textRepresentation);  }  綁定數(shù)據(jù)到view  用setViewBinder(null)的方式取消綁定  public void setViewImage(ImageView v, int value)  public void setViewImage(ImageView v, String value)  public void setViewText(TextView v, String text)  public Filter getFilter()  3.5         SimpleCursorAdapter  public class SimpleCursorAdapter extends ResourceCursorAdapter  demo  aipDemos/com.example.android.view/List2.java  List2.java,List3.java,List7.java  菜單路徑:API Demos/Views/Lists/  public SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to)  context  layout  c  Curor  from  to  public View newView(Context context, Cursor cursor, ViewGroup parent)  public View newDropDownView(Context context, Cursor cursor, ViewGroup parent)  public ViewBinder getViewBinder()  public void setViewBinder(ViewBinder viewBinder)  public void setViewImage(ImageView v, String value)  public void setViewText(TextView v, String text)  public void bindView(View view, Context context, Cursor cursor)  public int getStringConversionColumn()  public void setStringConversionColumn(int stringConversionColumn)  設(shè)置獲取from[stringConversionColumn]中數(shù)據(jù)  public CursorToStringConverter getCursorToStringConverter()  public void setCursorToStringConverter(  CursorToStringConverter cursorToStringConverter)  public static interface CursorToStringConverter {  CharSequence convertToString(Cursor cursor);  }  public CharSequence convertToString(Cursor cursor)  獲取from[stringConversionColumn]中數(shù)據(jù)  public void changeCursor(Cursor c)  3.6         HeaderViewListAdapter  public class HeaderViewListAdapter implements WrapperListAdapter, Filterable  private ListAdapter mAdapter;  ArrayListmHeaderViewInfos;  ArrayListmFooterViewInfos;  public HeaderViewListAdapter(ArrayListheaderViewInfos,  ArrayListfooterViewInfos,  ListAdapter adapter)  headerViewInfos  footerViewInfos  adapter  public class FixedViewInfo {  public View view;  public Object data;  public boolean isSelectable;  }  public int getHeadersCount()  public int getFootersCount()  public int getCount()  Header,F(xiàn)ooter,mAdapter總item數(shù)  public boolean isEmpty()  mAdapter是否為空  public boolean removeHeader(View v)  public boolean removeFooter(View v)  public boolean areAllItemsEnabled()  public ListAdapter getWrappedAdapter()  獲取mAdapter  四、            AbsListView4.1         概述  定義  public abstract class AbsListView extends AdapterViewimplements TextWatcher,          ViewTreeObserver.OnGlobalLayoutListener, Filter.FilterListener,          ViewTreeObserver.OnTouchModeChangeListener  包路徑  import android.widget.AbsListView;  子類信息  View  |___ ViewGroup         |___ AdapterView|___ AbsListView                       |___ GridView                       |___ ListView                              |___ ExpandableListView  4.2         部分方法  void setStackFromBottom(boolean stackFromBottom)  boolean isStackFromBottom()  單列  多列  Disable  Enable  Disable  Enable  1  1  2  3  2  1  4  5  1  2  2  3  4  5  void setScrollingCacheEnabled(boolean enabled)  boolean isScrollingCacheEnabled()  設(shè)置是否緩存卷動(dòng)項(xiàng),緩存則需額外的內(nèi)存,缺省為enable  void setCacheColorHint(int color)  int getCacheColorHint()  int getSolidColor()  緩存項(xiàng)背景顏色  int pointToPosition(int x, int y)  返回包含坐標(biāo)(x, y)的項(xiàng),沒有項(xiàng)包含該點(diǎn)則返回INVALID_POSITION  long pointToRowId(int x, int y)  void setTranscriptMode(int mode)  int getTranscriptMode()  TRANSCRIPT_MODE_DISABLED  當(dāng)數(shù)據(jù)發(fā)生變化不自動(dòng)滾動(dòng)  TRANSCRIPT_MODE_NORMAL  當(dāng)數(shù)據(jù)發(fā)生變化時(shí),最后一項(xiàng)正顯示在屏幕上,自動(dòng)滾動(dòng)到最低端  TRANSCRIPT_MODE_ALWAYS_SCROLL  當(dāng)數(shù)據(jù)發(fā)生變化時(shí),自動(dòng)滾動(dòng)到最低端  void setFilterText(String filterText)  void clearTextFilter()  boolean hasTextFilter()  過濾文本  void getFocusedRect(Rect r)  獲取焦點(diǎn)框區(qū)域  View getSelectedView()  void setSelector(int resID)  void setSelector(Drawable sel)  Drawable getSelector()  焦點(diǎn)框  void setDrawSelectorOnTop(boolean onTop)  true:Selector繪制在文字之上  void setScrollIndicators(View up, View down)  void reclaimViews(Listviews)  void setRecyclerListener(RecyclerListener listener)  LayoutParams generateLayoutParams(AttributeSet attrs)  void beforeTextChanged(CharSequence s, int start, int count, int after)  void onTextChanged(CharSequence s, int start, int before, int count)  void afterTextChanged(Editable s)  五、            ListView5.1         概述  定義  public class ListView extends AbsListView  包路徑  import android.widget.ListView  子類信息  View  |___ ViewGroup         |___ AdapterView|___ AbsListView                       |___ ListView                              |___ ExpandableListView  ListView顯示為垂直可滾動(dòng)的一列,所有item由ListAdapter提供。  5.2         部分方法  public ListView(Context context)  public ListView(Context context, AttributeSet attrs)  public ListView(Context context, AttributeSet attrs, int defStyle)  ListAdapter getAdapter()  void setAdapter(ListAdapter adapter)  設(shè)置listitem,adapter包含每一個(gè)item的數(shù)據(jù)并提供顯示數(shù)據(jù)的view  void addHeaderView(View v, Object data, boolean isSelectable)  void addHeaderView(View v)  在list頂端加headView,可以加多個(gè),按添加的順序顯示。isSelectable為可否被選擇。  必須在setAdapter()前調(diào)用,否則拋出IllegalStateException異常  int getHeaderViewsCount()  獲得headerView的數(shù)量  boolean removeHeaderView(View v)  必須在setAdapter()后調(diào)用,否則拋出NullPointerException異常(運(yùn)行期異常)。  void addFooterView(View v, Object data, boolean isSelectable)  void addFooterView(View v)  在list尾添加footerView,同addHeaderView()  必須在setAdapter()前后調(diào)用都可以  int getFooterViewsCount()  獲得footerView的數(shù)量  boolean removeFooterView(View v)  必須在setAdapter()后調(diào)用,否則拋出NullPointerException異常(運(yùn)行期異常)。  int getChoiceMode()  void setChoiceMode(int choiceMode)  ListView. CHOICE_MODE_NONE  ListView. CHOICE_MODE_SINGLE  ListView. CHOICE_MODE_MULTIPLE  void setSelection(int position)  設(shè)置第position為選擇狀態(tài)  void setSelectionFromTop(int position, int y)  設(shè)置第position為選擇狀態(tài),使position那項(xiàng)的位置在距離ListView頂端y的位置  void setSelectionAfterHeaderView()  使選擇項(xiàng)位置緊挨著HeaderView。  void setItemsCanFocus(boolean itemsCanFocus)  boolean getItemsCanFocus()  Drawable getDivider()  void setDivider(Drawable divider)  設(shè)置每?jī)蓚€(gè)item間的分割  int getDividerHeight()  void setDividerHeight(int height)  設(shè)置每?jī)蓚€(gè)item間空隙的高度  boolean isItemChecked(int position)  在單選或多選狀態(tài)下判斷第position項(xiàng)狀態(tài)  int getCheckedItemPosition()  在單選狀態(tài)下獲取選擇的那項(xiàng),多選無效  SparseBooleanArray getCheckedItemPositions()  非單選模式下有效  void clearChoices()  清除選擇  void setItemChecked(int position, boolean value)  設(shè)置position項(xiàng)的狀態(tài)  Parcelable onSaveInstanceState()  void onRestoreInstanceState(Parcelable state)  boolean performItemClick(View view, int position, long id)  boolean onTouchEvent(MotionEvent ev)  boolean dispatchKeyEvent(KeyEvent event)  boolean onKeyDown(int keyCode, KeyEvent event)  boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)  onKeyUp(int keyCode, KeyEvent event)  六、            ExpandableListView6.1         概述  定義  public class ExpandableListView extends ListView  包路徑  import android.widget.ExpandableListView;  子類信息  View  |___ ViewGroup         |___ AdapterView|___ AbsListView                       |___ ListView                              |___ ExpandableListView  ExpandableListView顯示為垂直可滾動(dòng)的一列,與ListView的區(qū)別是它的item分group和child兩層,item的children可以展開顯示,也可以疊起不顯示。所有item由ExpandableListAdapter提供。  ExpandableListItem的展開與否可以用setChildIndicator()或setGroupIndicator()來設(shè)置。  注意:如果ExpandableListView的parent高度設(shè)為WRAP_CONTENT,則不能指定ExpandableListView的layout_height為WRAP_CONTENT;如果parent高度一定則可以設(shè)為WRAP_CONTENT。  6.2         部分方法  void setAdapter(ListAdapter adapter)  拋出異常RuntimeException  ListAdapter getAdapter()  只獲取groupList  void setAdapter(ExpandableListAdapter adapter)  ExpandableListAdapter getExpandableListAdapter()  設(shè)置ExpandableListView數(shù)據(jù)  boolean collapseGroup(int groupPos)  合上groupPosition組,  boolean expandGroup(int groupPos)  展開groupPosition組,是展開狀態(tài)返回true  boolean isGroupExpanded(int groupPosition)  long getExpandableListPosition(int flatListPosition)  轉(zhuǎn)換一個(gè)ListView的position(flatListPosition)為ExpandableList的packedPosition,packedPosition由ExpandableList的groupPosition和childPosition計(jì)算而來。  int getFlatListPosition(long packedPosition)  packedPosition轉(zhuǎn)換為flatListPosition,  packedPosition類型為group時(shí)packedPosition跟groupPosition相等  packedPosition類型為child時(shí)packedPosition跟child所在的group的groupPosition相等  static int getPackedPositionType(long packedPosition)  packedPosition的類型,groupPosition還是childPosition  ExpandableListView.PACKED_POSITION_TYPE_GROUP  ExpandableListView.PACKED_POSITION_TYPE_CHILD  ExpandableListView.PACKED_POSITION_TYPE_NULL  static int getPackedPositionGroup(long packedPosition)  返回groupPosition  static int getPackedPositionChild(long packedPosition)  如果packedPosition的類型是PACKED_POSITION_TYPE_CHILD,返回childPosition  static long getPackedPositionForChild(int groupPosition, int childPosition)  生成child的packedPosition  static long getPackedPositionForGroup(int groupPosition)  生成group的packedPosition  long getSelectedPosition()  long getSelectedId()  void setGroupIndicator(Drawable groupIndicator)  groupItem的標(biāo)識(shí)  void setIndicatorBounds(int left, int right)  groupItem標(biāo)識(shí)的位置  void setChildIndicator(Drawable childIndicator)  childItem的標(biāo)識(shí)  void setChildIndicatorBounds(int left, int right)  childItem標(biāo)識(shí)的位置,從left開始到right結(jié)束,right>left才顯示出來  left,right都可以指定ExpandableListView.CHILD_INDICATOR_INHERIT,繼承g(shù)roupItem表識(shí)的位置,即通過setIndicatorBounds()設(shè)置的位置  void setChildDivider(Drawable childDivider)  void setSelectedGroup(int groupPosition)  boolean setSelectedChild(int groupPosition, int childPosition, boolean shouldExpandGroup)  public void setOnChildClickListener(OnChildClickListener onChildClickListener)  設(shè)置childItem點(diǎn)擊監(jiān)聽器  public void setOnGroupClickListener(OnGroupClickListener onGroupClickListener)  設(shè)置groupItem點(diǎn)擊監(jiān)聽器  public void setOnGroupCollapseListener (  OnGroupCollapseListener onGroupCollapseListener)  設(shè)置groupItem合上時(shí)觸發(fā)的監(jiān)聽器  public void setOnGroupExpandListener (                     OnGroupExpandListener onGroupExpandListener)  設(shè)置groupItem展開時(shí)觸發(fā)的監(jiān)聽器  public void setOnItemClickListener(OnItemClickListener l)  觸發(fā)ItemClick的itemPos是flatListPosition,盡量用setOnChildClickListener()和setOnGroupClickListener()代替這個(gè)方法。  6.3         ExpandableListAdapter  BaseExpandableListAdapter  CursorTreeAdapter  SimpleExpandableListAdapter  ResourceCursorTreeAdapter  ExpandableListAdapter  SimpleCursorTreeAdapter  黑色文字為接口紅色文字為類斜體字為抽象類  6.4         SimpleExpandableListAdapter  public class SimpleExpandableListAdapter extends BaseExpandableListAdapter  public SimpleExpandableListAdapter(Context context,              List> groupData, int groupLayout,              String[] groupFrom, int[] groupTo,              List>> childData,              int childLayout, String[] childFrom, int[] childTo)  public SimpleExpandableListAdapter(Context context,              List> groupData, int expandedGroupLayout,              int collapsedGroupLayout, String[] groupFrom, int[] groupTo,              List>> childData,              int childLayout, String[] childFrom, int[] childTo)  public SimpleExpandableListAdapter(Context context,              List> groupData, int expandedGroupLayout,              int collapsedGroupLayout, String[] groupFrom, int[] groupTo,              List>> childData,              int childLayout, int lastChildLayout, String[] childFrom,              int[] childTo)  groupData  grouplist數(shù)據(jù)  groupLayout  grouplist loyout資源文件  expandedGroupLayout  grouplist  collapsedGroupLayout  grouplist  groupFrom  抽取groupData的Map的哪幾列數(shù)據(jù)  groupTo  由groupFrom獲取的數(shù)據(jù)生成view的viewId  childData  childlist數(shù)據(jù)  childLayout  childlistloyout資源文件  lastChildLayout  childFrom  抽取childlist的Map的哪幾列數(shù)據(jù)  childTo  由childFrom獲取的數(shù)據(jù)生成view的viewId  public int getChildrenCount(int groupPosition)  public Object getChild(int groupPosition, int childPosition)  public long getChildId(int groupPosition, int childPosition)  public View getChildView(int groupPosition, int childPosition, boolean isLastChild,              View convertView, ViewGroup parent)  public View newChildView(boolean isLastChild, ViewGroup parent)  public int getGroupCount()  public Object getGroup(int groupPosition)  public long getGroupId(int groupPosition)  public View getGroupView(int groupPosition, boolean isExpanded, View convertView,              ViewGroup parent)  public View newGroupView(boolean isExpanded, ViewGroup parent)  public boolean isChildSelectable(int groupPosition, int childPosition)  public boolean hasStableIds()  6.5         SimpleCursorTreeAdapter  public abstract class SimpleCursorTreeAdapter extends ResourceCursorTreeAdapter  public SimpleCursorTreeAdapter(Context context, Cursor cursor, int collapsedGroupLayout,              int expandedGroupLayout, String[] groupFrom, int[] groupTo, int childLayout,              int lastChildLayout, String[] childFrom, int[] childTo)  public SimpleCursorTreeAdapter(Context context, Cursor cursor, int collapsedGroupLayout,              int expandedGroupLayout, String[] groupFrom, int[] groupTo,              int childLayout, String[] childFrom, int[] childTo)  public SimpleCursorTreeAdapter(Context context, Cursor cursor, int groupLayout,              String[] groupFrom, int[] groupTo, int childLayout, String[] childFrom,              int[] childTo)  與SimpleExpandableListAdapter不同的是List> groupData改為Cursor cursor,共有方法都類似。  七、            ListActivity7.1         概述  定義  public class ListActivity extends Activity  包路徑  import android.app.ListActivity  子類信息  Context  |___ ContextWrapper         |___ ContextThemeWrapper                |___ Activity                       |___ ListActivity  繼承Activity,封裝一個(gè)ListView成員  demo  aipDemos/com.example.android.view/List1.java  List1.java ~ List14.java  菜單路徑:API Demos/Views/Lists/  7.2         部分方法  public void onContentChanged()  public void setListAdapter(ListAdapter adapter)  public ListAdapter getListAdapter()  public void setSelection(int position)  public int getSelectedItemPosition()  public long getSelectedItemId()  public ListView getListView()  獲取ListView對(duì)象,可以使用ListView的方法  7.3         ExpandableListActivity  public class ExpandableListActivity extends Activity implements          OnCreateContextMenuListener,  ExpandableListView.OnChildClickListener, ExpandableListView.OnGroupCollapseListener,          ExpandableListView.OnGroupExpandListener  繼承Activity封裝一個(gè)ExpandableListView對(duì)象  八、            GridView8.1         概述  定義  public class GridView extends AbsListView  包路徑  import android.widget.AbsListView  子類信息  View  |___ ViewGroup         |___ AdapterView|___ AbsListView                       |___ GridView  多行多列可垂直方向滾動(dòng),只支持先行后列垂直方向滾動(dòng)的模式;不支持先列后行水平方向滾動(dòng)的模式  支持  不支持  1  2  3  4  5  6  7  1  4  7  2  5  3  6  demo  aipDemos/com.example.android.view/Grid1.java  Grid1.java ~ Grid2.java  菜單路徑:API Demos/Views/Grid/  8.2         部分方法  top padding  bottom padding  left padding  right padding  vertical spacing  horizontal spacing  void setVerticalSpacing(int verticalSpacing);  設(shè)置垂直方向行間距  void setHorizontalSpacing(int horizontalSpacing);  設(shè)置水平方向列間距  void setColumnWidth(int columnWidth);  設(shè)置列寬  void setNumColumns(int numColumns);  設(shè)置列數(shù)  void setGravity(int gravity);  設(shè)置item對(duì)齊方式  Gravity.TOP  Gravity.BOTTOM  Gravity.LEFT  缺省  Gravity.RIGHT  Gravity.CENTER_VERTICAL  Gravity.CENTER_HORIZONTAL  Gravity.CENTER  Gravity.FILL_VERTICAL  Gravity.FILL_HORIZONTAL  Gravity.FILL  Gravity.CLIP_VERTICAL  Gravity.CLIP_HORIZONTAL  int getStretchMode()  void setStretchMode(int stretchMode)  設(shè)置填充GridView時(shí)的方式  GridView.NO_STRETCH  使用設(shè)置的列寬和列間距排版,無視GridView的寬度  GridView.STRETCH_SPACING  拉伸列間距,根據(jù)列寬、列數(shù)和GridView的寬度計(jì)算列間距。Item+Space+Item  GridView.STRETCH_SPACING_UNIFORM  拉伸列間距,計(jì)算方式與  GridView.STRETCH_SPACING不同。  Space+Item+Space+Item+Space  GridView.STRETCH_COLUMN_WIDTH  拉伸列寬,根據(jù)列間距、列數(shù)和GridView的寬度計(jì)算列寬。  ListAdapter getAdapter()  void setAdapter(ListAdapter adapter)  設(shè)置item列表  public void setSelection(int position)  九、            AbsSpinner9.1         概述  定義  public abstract class AbsSpinner extends AdapterView包路徑  import android.widget.AbsSpinner;  子類信息  View  |___ ViewGroup         |___ AdapterView|___ AbsSpinner                       |___ Gallery                       |___ Spinner  9.2         部分方法  void setAdapter(SpinnerAdapter adapter)  SpinnerAdapter getAdapter()  void setSelection(int position, boolean animate)  void setSelection(int position)  int getCount()  int pointToPosition(int x, int y)  Parcelable onSaveInstanceState()  void onRestoreInstanceState(Parcelable state)  十、            Gallery10.1     概述  定義  public class Gallery extends AbsSpinner implements GestureDetector.OnGestureListener  包路徑  import android.widget.Gallery;  子類信息  View  |___ ViewGroup         |___ AdapterView|___ AbsSpinner                       |___ Gallery  items水平方向滾動(dòng)顯示,滾動(dòng)停止時(shí)選擇項(xiàng)停在屏幕正中。  demo  aipDemos/com.example.android.view/Gallery1.java  Gallery1.java ~ Gallery2.java  菜單路徑:API Demos/Views/Gallery/  10.2     部分方法  void setCallbackDuringFling(boolean shouldCallback)  滑動(dòng)過程中是否每項(xiàng)都調(diào)用getOnItemSelectedListener()注冊(cè)的callback  false:最后選中的一項(xiàng)才調(diào)用callback  true:所有項(xiàng)都調(diào)用callback  void setAnimationDuration(int animationDurationMillis)  設(shè)置反彈回屏幕正中這部分的動(dòng)畫時(shí)間間隔,單位毫秒,缺省為400ms。  void setSpacing(int spacing)  設(shè)置兩項(xiàng)之間的間距,缺省為0,單位象素  void setUnselectedAlpha(float unselectedAlpha)  設(shè)置未選中項(xiàng)的alpha值 0~1.0  十一、           Spinner11.1     概述  定義  public class Spinner extends AbsSpinner implements OnClickListener  包路徑  import android.widget.Spinner;  子類信息  View  |___ ViewGroup         |___ AdapterView|___ AbsSpinner                       |___ Spinner  在一個(gè)單行文本框中,同時(shí)只顯示一個(gè)有序列表中的一個(gè)項(xiàng),點(diǎn)擊彈出一個(gè)下拉單選對(duì)話框,從中進(jìn)行選擇。  系統(tǒng)自帶布局文件:  simple_spinner_dropdown_item.xml  simple_spinner_item.xml  demo  aipDemos/com.example.android.view/Spinner1.java  菜單路徑:API Demos/Views/Spinner/  11.2     部分方法  public int getBaseline()  public void setOnItemClickListener(OnItemClickListener l)  拋出異常RuntimeException  public boolean performClick()  彈出下拉對(duì)話框  public void onClick(DialogInterface dialog, int which)  public void setPrompt(CharSequence prompt)  public void setPromptId(int promptId)  public CharSequence getPrompt()  設(shè)置下拉菜單標(biāo)題  十二、           LinearLayout12.1     概述  定義  public class LinearLayout extends ViewGroup  包路徑  import android.widget.LinearLayout;  子類信息  View  |___ ViewGroup         |___ LinearLayout                |___ RadioGroup                |___ TabWidget                |___ TableLayout                |___ TableRow                |___ ZoomControls                |___ NumberPicker  LinearLayout可以設(shè)置位水平的一行或垂直的一列,所有子元素按加入順序排列,通過setOrientation()來設(shè)置行模式還是列模式,缺省為行模式。通過setGravity()設(shè)置對(duì)齊方式。  也可以對(duì)單個(gè)子元素制定weight,允許子元素填充屏幕上的剩余空間,剩余空間安指定的比例分配。  demo  aipDemos/com.example.android.view/linear_layout_1.java  linear_layout_1.java ~ linear_layout_10.java  菜單路徑:API Demos/Views/ Layouts/LinearLayout/  12.2     部分方法  public LinearLayout(Context context)  public LinearLayout(Context context, AttributeSet attrs)  public boolean isBaselineAligned()  public void setBaselineAligned(boolean baselineAligned)  public int getBaseline()  獲取baseline距離頂端的距離,不支持baseline對(duì)齊返回-1  public int getBaselineAlignedChildIndex()  public void setBaselineAlignedChildIndex(int i)  public float getWeightSum()  public void setWeightSum(float weightSum)  public void setOrientation(int orientation)  public int getOrientation()  HORIZONTAL:行模式  VERTICAL:列模式  public void setGravity(int gravity)  public void setHorizontalGravity(int horizontalGravity)  public void setVerticalGravity(int verticalGravity)  對(duì)齊方式  public LayoutParams generateLayoutParams(AttributeSet attrs)  public static class LayoutParams extends ViewGroup.MarginLayoutParams  增加了一個(gè)參數(shù)weight  public LayoutParams(int width, int height, float weight)  比如3個(gè)layout排成一行,分別為ly1, ly2, ly3  width值分別為width1,width2,width3  FILL_PARENT的寬度為WIDTH  weight值分別為weight1, weight2, weight3  只要weight1,weight2,weight3不同時(shí)為0,則3個(gè)layout總寬度變?yōu)閃IDTH  ly1的寬度為  對(duì)weight未負(fù)數(shù),width1+width2+width3 >= WIDTH未做測(cè)試  12.3     LinearLayout.LayoutParams  public static class LayoutParams extends ViewGroup.MarginLayoutParams  public float weight;              //增加weight屬性  public int gravity = -1;  public LayoutParams(int width, int height, float weight)  12.4     RadioGroup  demo  aipDemos/com.example.android.view/RadioGroup1.java  菜單路徑:API Demos/Views/ Radio Group/  一列RadioButton  public void setOnHierarchyChangeListener(OnHierarchyChangeListener listener)  子項(xiàng)有變化時(shí)觸發(fā)的監(jiān)聽器,增加/刪除項(xiàng)  public void check(int id)  設(shè)置id項(xiàng)為選擇  public int getCheckedRadioButtonId()  獲取選擇項(xiàng)的id  public void clearCheck()  清除選擇狀態(tài)  public void setOnCheckedChangeListener(OnCheckedChangeListener listener)  RadioButton狀態(tài)改變監(jiān)聽器  12.5     TabWidget  通常用作TabHost的子元素,單獨(dú)使用同LinearLayout。  12.6     TableRow  通常用作TableLayout子元素,單獨(dú)使用同LinearLayout。  12.7     ZoomControls  系統(tǒng)帶布局文件  zoom_controls.xml  public void setOnZoomInClickListener(OnClickListener listener)  public void setOnZoomOutClickListener(OnClickListener listener)  public void setZoomSpeed(long speed)  public boolean onTouchEvent(MotionEvent event)  public void show()  淡入  public void hide()  淡出消失  public void setIsZoomInEnabled(boolean isEnabled)  public void setIsZoomOutEnabled(boolean isEnabled)  public boolean hasFocus()  十三、           TableLayout13.1     概述  定義  public class TableLayout extends LinearLayout  包路徑  import android.widget.TableLayout;  子類信息  View  |___ ViewGroup         |___ LinearLayout                |___ TableLayout  TableLayout將子元素的位置分配到行或列中,一個(gè)TableLayout由許多TableRow組成,每個(gè)TableRow都定義一個(gè)row,TableLayout不顯示row、column或cell的邊框線,每個(gè)row擁有0個(gè)或多個(gè)cell,每個(gè)cell擁有一個(gè)view對(duì)象。列可以被隱藏setColumnCollapsed(),也可以設(shè)置為伸展從而填充可利用的屏幕空間setColumnStretchable(),也可以設(shè)置為強(qiáng)制收縮直到表各匹配屏幕大小setColumnShrikable()。  TableLayout寬始終為FILL_PARENT,TableRow的高始終未WRAP_CONTEN。  demo  aipDemos/com.example.android.view/TableLayout1.java  TableLayout1.java ~ TableLayout12.java  菜單路徑:API Demos/Views/ Layouts/TableLayout  13.2     部分方法  public boolean isShrinkAllColumns()  public void setShrinkAllColumns(boolean shrinkAllColumns)  是否所有列可收縮  public boolean isStretchAllColumns()  public void setStretchAllColumns(boolean stretchAllColumns)  是否所有列可拉伸  public void setColumnCollapsed(int columnIndex, boolean isCollapsed)  public boolean isColumnCollapsed(int columnIndex)  columnIndex列是否隱藏,必須是TableRow的列才能隱藏  public void setColumnStretchable(int columnIndex, boolean isStretchable)  public boolean isColumnStretchable(int columnIndex)  columnIndex列是否可拉伸  public void setColumnShrinkable(int columnIndex, boolean isShrinkable)  public boolean isColumnShrinkable(int columnIndex)  columnIndex列是否可收縮  13.3     TableLayout.LayoutParams  public static class LayoutParams extends LinearLayout.LayoutParams  重載了構(gòu)造函數(shù)強(qiáng)制設(shè)width為FILL_PARENT  13.4     TableRow.LayoutParams  public static class LayoutParams extends LinearLayout.LayoutParams  public int column;  //第幾列  public int span;      //占幾列寬  public LayoutParams(int column)  十四、           FrameLayout14.1     概述  定義  public class FrameLayout extends ViewGroup  包路徑  import android.widget.FrameLayout  子類信息  View  |___ ViewGroup         |___ FrameLayout                |___ DatePicker                |___ TimePicker                |___ MediaController                |___ ScrollView                |___ TabHost                |___ ViewAnimator                       |___ ViewFlipper                       |___ ViewSwitcher                              |___ ImageSwitcher                              |___ TextSwitcher  FrameLayout定制為屏幕上一個(gè)空白備用區(qū)域,可以在其中填充一個(gè)單一對(duì)象。所有的子元素將會(huì)固定在屏幕的左上角,不能為FrameLayout中一個(gè)子元素制定位置,后一個(gè)子元素將直接在前一個(gè)子元素之上進(jìn)行覆蓋填充,把他們?nèi)炕虿糠謸踝。ǔ呛笠粋€(gè)子元素是透明的)。  14.2     部分方法  public FrameLayout(Context context)  public FrameLayout(Context context, AttributeSet attrs)  public FrameLayout(Context context, AttributeSet attrs, int defStyle)  public void setForegroundGravity(int foregroundGravity)  設(shè)置前景對(duì)齊方式,缺省為Gravity.FILL  public Drawable getForeground()  public void setForeground(Drawable drawable)  設(shè)置drawable,drawable是一個(gè)可繪制的“設(shè)備”,drawable顯示在所有child之上  public void draw(Canvas canvas)  手動(dòng)把canvas所在的view顯示出來,不用重載該函數(shù),注意與onDraw(Canvas)的區(qū)別  public boolean gatherTransparentRegion(Region region)  public void setMeasureAllChildren(boolean measureAll)  public boolean getConsiderGoneChildrenWhenMeasuring()  public LayoutParams generateLayoutParams(AttributeSet attrs)  14.3     FrameLayout. LayoutParams  public static class LayoutParams extends MarginLayoutParams  public int gravity = -1;  public LayoutParams(Context c, AttributeSet attrs)  public LayoutParams(int width, int height)  14.4     DatePicker  由3個(gè)NumberPicker組成,系統(tǒng)自帶一個(gè)layout文件:  \cupcake\frameworks\base\core\res\res\layout\date_picker.xml,  這個(gè)缺省布局方式為水平LinearLayout,順序?yàn)镸onth/Day/Year  這個(gè)控件dayOfMont的范圍校驗(yàn)做的還不好,比如當(dāng)前時(shí)間是2009/3/31,月份減一后為2009/2/31,而這個(gè)日期是非法的,但設(shè)置為系統(tǒng)日期是可以成功的,結(jié)果為2009/3/3。  demo  aipDemos/com.example.android.view/DateWidgets1.java  DateWidgets1.java ~ DateWidgets2.java  菜單路徑:API Demos/Views/Date Widgets/  public void setEnabled(boolean enabled)  public void updateDate(int year, int monthOfYear, int dayOfMonth)  monthOfYear:0~11  year:1900~2100  dayOfMonth:1~31  public void init(int year, int monthOfYear, int dayOfMonth,              OnDateChangedListener onDateChangedListener)  public void setEnabled(boolean enabled)  public int getYear()  public int getMonth()  public int getDayOfMonth()  14.5     TimePicker  demo同上  public void setEnabled(boolean enabled)  public void setOnTimeChangedListener(  OnTimeChangedListener onTimeChangedListener)  public Integer getCurrentHour()  public void setCurrentHour(Integer currentHour)  public void setIs24HourView(Boolean is24HourView)  public boolean is24HourView()  public Integer getCurrentMinute()  public void setCurrentMinute(Integer currentMinute)  public int getBaseline()  14.6     MediaController  demo  aipDemos/com.example.android.media/VideoViewDemo.java  14.7     ScrollView  demo  aipDemos/com.example.android.view/ScrollView1.java  ScrollView1.java ~ ScrollView2.java  aipDemos/com.example.android.view/InternalSelectionScroll.java  菜單路徑:API Demos/Views/ Layouts/ScrollView/  ScrollView只支持垂直方向滾動(dòng),只能有一個(gè)子對(duì)象,這個(gè)子對(duì)象的大小可以超過屏幕大小。這個(gè)子對(duì)象不能是ListView或TextView,因這兩個(gè)view是自己管理如何滾動(dòng)。這個(gè)子對(duì)象通常使用LinearLayout  public void addView(View child)  public void addView(View child, int index)  public void addView(View child, ViewGroup.LayoutParams params)  public void addView(View child, int index, ViewGroup.LayoutParams params)  只能有一個(gè)子元素,在已有一個(gè)子元素時(shí)再調(diào)用會(huì)拋出異常IllegalStateException()  public int getMaxScrollAmount()  public boolean isFillViewport()  public void setFillViewport(boolean fillViewport)  true:拉伸高度到viewport的高  public boolean isSmoothScrollingEnabled()  public void setSmoothScrollingEnabled(boolean smoothScrollingEnabled)  true:滾動(dòng)過程用動(dòng)畫過渡  public boolean pageScroll(int direction)  翻頁  public boolean fullScroll(int direction)  翻到底部或頂部  public boolean arrowScroll(int direction)  翻項(xiàng)  View.FOCUS_DOWN  View.FOCUS_UP  public final void smoothScrollBy(int dx, int dy)  相對(duì)目前位置滾動(dòng)(x, y)  public final void smoothScrollTo(int x, int y)  滾動(dòng)到絕對(duì)位置(x, y)  public void scrollTo(int x, int y)  無動(dòng)畫效果滾動(dòng)  public void fling(int velocityY)  14.8     TabHost  demo  aipDemos/com.example.android.view/Tabs1.java  Tabs1.java~ Tabs3.java  菜單路徑:API Demos/Views/ Layouts/LinearLayout/  對(duì)應(yīng)TabActivity  TabHost由TabWidget,TabContent組成。  TabWidget包含多個(gè)TabSpec;TabContent是FrameLayout.  TabSpec由tag,indictor,content組成,content可以是  1.ViewId;2.intent;3.TabHost.TabContentFactory。  內(nèi)部接口TabHost.TabContentFactory  public interface TabContentFactory {  View createTabContent(String tag);  }  在xml文件中定義TabHost需注意兩點(diǎn):  1.TabWidget的id必須指定為"@android:id/tabs",否則會(huì)有RuntimeException2.a(chǎn)ddTab()之前需調(diào)用setup()方法,繼承TabActivity則不需要  public TabSpec newTabSpec(String tag)  創(chuàng)建一個(gè)tab標(biāo)簽,tab標(biāo)簽由3部分組成:tag文字,label文字/圖片,content  內(nèi)部類TabHost.TabSpec,它的每個(gè)函數(shù)都返回this對(duì)象,便于鏈?zhǔn)奖磉_(dá),比如:  tabHost.addTab(tabHost.newTabSpec("tab1")                  .setIndicator("tab1")                  .setContent(R.id.view1));  public class TabSpec {  public TabSpec setIndicator(CharSequence label);  public TabSpec setIndicator(CharSequence label, Drawable icon);  public TabSpec setContent(int viewId);  public TabSpec setContent(TabContentFactory contentFactory);  public TabSpec setContent(Intent intent);  };  public void setup()  public void setup(LocalActivityManager activityGroup)  從xml創(chuàng)建TabHost 才須調(diào)setup(),如果TabSpec的content是intent需調(diào)用帶參數(shù)的setup()  public void addTab(TabSpec tabSpec)  public void clearAllTabs()  public void setCurrentTabByTag(String tag)  public void setCurrentTab(int index)  public int getCurrentTab()  public String getCurrentTabTag()  public View getCurrentTabView()  public View getCurrentView()  public TabWidget getTabWidget()  public FrameLayout getTabContentView()  public void onTouchModeChanged(boolean isInTouchMode)  public void setOnTabChangedListener(OnTabChangeListener l)  標(biāo)簽變化觸發(fā)的監(jiān)聽器  14.9     ViewAnimator  因FrameLayout是多個(gè)子元素占同樣的顯示區(qū)域,則在不同子元素切換顯示時(shí)可以加動(dòng)畫效果。通常是當(dāng)前顯示的view消失,下一個(gè)顯示的view出現(xiàn)。  public void setDisplayedChild(int whichChild)  public void setDisplayedChild(int whichChild)  public int getDisplayedChild()  public void showNext()  public void showPrevious()  public void addView(View child, int index, ViewGroup.LayoutParams params)  重載了該方法,在加第一個(gè)view的狀態(tài)為View.VISIBLE,之后加的view狀態(tài)都是View.GONE  public View getCurrentView()  public Animation getInAnimation()  public void setInAnimation(Animation inAnimation)  public Animation getOutAnimation()  public void setOutAnimation(Animation outAnimation)  public void setInAnimation(Context context, int resourceID)  public void setOutAnimation(Context context, int resourceID)  public void setAnimateFirstView(boolean animate)  14.10 ViewFlipper  14.11 ViewSwitcher  14.12 ImageSwitcher  demo  aipDemos/com.example.android.view/ImageSwitcher1.java  菜單路徑:API Demos/Views/ ImageSwitcher/  14.13 TextSwitcher  demo  aipDemos/com.example.android.view/TextSwitcher1.java  菜單路徑:API Demos/Views/ TextSwitcher/  十五、           RelativeLayout15.1     概述  定義  public class RelativeLayout extends ViewGroup  包路徑  import android.widget.RelativeLayout;  子類信息  View  |___ ViewGroup         |___ RelativeLayout                |___ DialerFilter                |___ TwoLineListItem  RelativeLayout的child view位置可以用相對(duì)于其他元素或父元素的位置來描述。如果Y的位置依賴于X,則X需先于Y描述。  需要注意的是不要循環(huán)依賴,比如RelativeLayout的高設(shè)為WRAP_CONTENT,其child設(shè)為ALIGN_PARENT_BOTTOM  demo  aipDemos/com.example.android.view/RelativeLayout1.java  RelativeLayout1.java ~ RelativeLayout2.java  菜單路徑:API Demos/Views/Layouts/RelativeLayout/  15.2     部分方法  public void setIgnoreGravity(int viewId)  public void setGravity(int gravity)  public void setHorizontalGravity(int horizontalGravity)  public void setVerticalGravity(int verticalGravity)  public int getBaseline()  public LayoutParams generateLayoutParams(AttributeSet attrs)  public static class LayoutParams extends ViewGroup.MarginLayoutParams  LEFT_OF              位于指定child的左邊  RIGHT_OF  ABOVE  BELOW  ALIGN_BASELINE       ALIGN_LEFT                     相對(duì)指定child的左邊對(duì)齊  ALIGN_TOP  ALIGN_RIGHT  ALIGN_BOTTOM  ALIGN_PARENT_LEFT  ALIGN_PARENT_RIGHT  ALIGN_PARENT_TOP  ALIGN_PARENT_BOTTOM  CENTER_IN_PARENT  CENTER_HORIZONTAL  CENTER_VERTICAL  15.3     RelativeLayout.LayoutParams  public static class LayoutParams extends ViewGroup.MarginLayoutParams  public boolean alignWithParent;    public LayoutParams(Context c, AttributeSet attrs)  public LayoutParams(int w, int h)  public LayoutParams(ViewGroup.LayoutParams source)  public LayoutParams(ViewGroup.MarginLayoutParams source)  public void addRule(int verb)  只用于添加相對(duì)于parent的規(guī)則,可用addRule(verb, RelativeLayout.TRUE)代替,RelativeLayout.TRUE的值為-1  public void addRule(int verb, int anchor)  verb為相對(duì)于兄弟位置,則anchor必須為有效的兄弟id設(shè)置才生效,否則無效  verb為相對(duì)于parent位置,anchor無論設(shè)為何值都生效  public int[] getRules()  15.4     DialerFilter  15.5     TwoLineListItem  十六、           AbsoluteLayout16.1     概述  定義  public class AbsoluteLayout extends ViewGroup  包路徑  import android.widget.Absolutelayout;  子類信息  View  |___ ViewGroup         |___ AbsoluteLayout                |___ WebView  AbsoluteLayout可以對(duì)其子元素指定準(zhǔn)確的x/y坐標(biāo)值,允許元素之間相互重疊,不推薦使用。  16.2     部分方法  public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs)  16.3     AbsoluteLayout. LayoutParams  public static class LayoutParams extends ViewGroup.LayoutParams  public int x;    // 在ViewGroup.LayoutParams基礎(chǔ)上增加坐標(biāo)(x, y)  public int y;  public LayoutParams(int width, int height, int x, int y)  public LayoutParams(Context c, AttributeSet attrs)  public LayoutParams(ViewGroup.LayoutParams source)  十七、           WebView17.1     概述  定義  public class WebView extends AbsoluteLayout          implements ViewTreeObserver.OnGlobalFocusChangeListener,          ViewGroup.OnHierarchyChangeListener  包路徑  import android.webkit.WebView;  子類信息  View  |___ ViewGroup         |___ AbsoluteLayout                |___ WebView  WebView用于顯示網(wǎng)頁,用于可滾動(dòng)顯示的web瀏覽器或簡(jiǎn)單顯示在線內(nèi)容的Activity。用WebKit顯示網(wǎng)頁和在歷史記錄向前向后操作、放大縮小、搜索文字demo  aipDemos/com.example.android.view/webview_1.java  菜單路徑:API Demos/Views/WebView/  17.2     部分方法  public void clearCache(boolean includeDiskFiles)  public void goBack()  public void goForward()  public String getUrl()  public String getTitle()  public void reload()  public void loadUrl(String url)  public boolean zoomIn()  public boolean zoomOut()  public void goBackOrForward(int steps)

在網(wǎng)站上搜索的時(shí)候看到了windowManager、window、viewGroup中的實(shí)現(xiàn)原理,看了一下,覺得不錯(cuò)所以一并貼到這里來了。

介紹addview方法,在windowManager、window、viewGroup中的實(shí)現(xiàn)原理。首先將介紹這些類結(jié)構(gòu)關(guān)系,然后分析其內(nèi)在聯(lián)系,介紹實(shí)現(xiàn)原理,最后介紹重要的一個(gè)參數(shù)windowManager.layoutParams。 文章預(yù)計(jì)分為三個(gè)部分。 一、首先介紹一下上述接口、類的結(jié)構(gòu)

接口:windowManager

用來在應(yīng)用與window之間的管理接口,管理窗口順序,消息等 public interface WindowManager extends android.view.ViewManager      抽象類:window

定義窗口樣式和行為的抽象基類,用于作為頂層的view加到windowManager中。

唯一實(shí)現(xiàn)了這個(gè)抽象類的是PhoneWindow,實(shí)例化PhoneWindow需要一個(gè)窗口

public abstract class Window

其中有一個(gè)很重要的內(nèi)部類

private class LocalWindowManager extends WindowManagerImpl.CompatModeWrapper{...};

抽象類:viewGroup

包含其他view的容器,layouts和view 容器的基類。

public abstract class ViewGroup extends View implements ViewParent, ViewManager

相關(guān)接口:ViewParent

定義了一個(gè)view parent 的要負(fù)責(zé)的功能以及view和parent view之間的關(guān)聯(lián)

public interface ViewParent {public void requestLayout();

public void createContextMenu(ContextMenu menu);

public void bringChildToFront(View child);

.....

}

viewManager

用來添加和移除activity中的view的接口 public interface ViewManager {public void addView(View view, ViewGroup.LayoutParams params);     public void updateViewLayout(View view, ViewGroup.LayoutParams params);     public void removeView(View view); } 二.他們之間的內(nèi)在關(guān)系。

1. 對(duì)于view來說,添加到viewGroup中是通過addView();方式來實(shí)現(xiàn)的,在addView中實(shí)際上使用的是:

addViewInner(child, index, params, false);

流程是: 1.首先是對(duì)子View是否已經(jīng)包含到一個(gè)父容器中

2.對(duì)子View布局參數(shù)的處理

3.調(diào)用addInArray來添加View

4.設(shè)置父View為當(dāng)前的ViewGroup

5.焦點(diǎn)的處理

6.當(dāng)前View的AttachInfo信息

7.View樹改變的監(jiān)聽

8.子View中的mViewFlags的設(shè)置                              主要是通過    addInArray添加view,添加的實(shí)現(xiàn)為system.arrayCopy(....);

2. 對(duì)于viewGroup來說,都會(huì)顯示在在一個(gè)窗口中,每個(gè)都有一個(gè)父節(jié)點(diǎn)mParent,,最頂上的節(jié)點(diǎn)也是一個(gè)viewGroup,也就是decorView。

對(duì)于每個(gè)activity只有一個(gè)decorView也就是ViewRoot,只有一個(gè)window,window的獲取是通過下面方法獲取的。

Window mWindow = PolicyManager.makeNewWindow(this); 復(fù)制代碼 在activity中使用setContentView(),其實(shí)是使用了 window.setContentView()完成的,window.setcontentView,

還是通過LocalWindowManager.addView(view, params)來實(shí)現(xiàn)的。這里L(fēng)ocalWindowManager是實(shí)現(xiàn)了WindowManagerImpl.CompatModeWrapper

,本質(zhì)上就是WindowManager、viewManager接口中的addvidew方法。

3.  對(duì)于windowManager來說一個(gè)系統(tǒng)只有一個(gè),它是由系統(tǒng)底層實(shí)現(xiàn)的,用于負(fù)責(zé)調(diào)度當(dāng)前顯示那個(gè)窗口,消息處理我們獲得一個(gè)windowManager的方式如下: WindowManager windowManager = (WindowManager)context().getSystemService(                                     Context.WINDOW_SERVICE); 復(fù)制代碼 這里windowManager其實(shí)是一個(gè)接口,而通過getSystemService的方式。通過這個(gè)方式可以獲取很多的系統(tǒng)服務(wù),比如電話、鬧鐘、電源管理等等。

同時(shí)windowManager和幾個(gè)類之間的內(nèi)在聯(lián)系如下:

windowManager類圖關(guān)系.jpg (67.46 KB, 下載次數(shù): 0)

下載附件  保存到相冊(cè)

2013-10-10 19:02 上傳

責(zé)任編輯:

標(biāo)簽:

相關(guān)推薦:

精彩放送:

新聞聚焦
Top 主站蜘蛛池模板: 连云港市| 武冈市| 原平市| 唐河县| 攀枝花市| 阿图什市| 康定县| 滨海县| 磐安县| 福泉市| 绥德县| 青龙| 平罗县| 唐海县| 乌拉特前旗| 湾仔区| 巴彦县| 包头市| 德昌县| 巴中市| 泸溪县| 泽州县| 同心县| 清新县| 辽源市| 衡阳县| 米泉市| 孟州市| 永平县| 临清市| 报价| 梅河口市| 丹寨县| 新乐市| 永济市| 崇文区| 交口县| 奇台县| 永胜县| 沈丘县| 高安市|