該標(biāo)簽用于指定屏幕內(nèi)的焦點View。
例如我們點擊tab鍵或enter鍵焦點自動進(jìn)入下一個輸入框
用法: 將標(biāo)簽置于Views標(biāo)簽內(nèi)部
1
<EditText id="@+id/text"
2
android:layout_width="fill_parent"
3
android:layout_height="wrap_content"
4
android:layout_weight="0"
5
android:paddingBottom="4">
6
<requestFocus />
7
</EditText>
ml布局里面設(shè)置文字的外觀:
如“android:textAppearance=“?android:attr/textAppearanceLargeInverse”這里引用的是系統(tǒng)自帶的一個外觀,
?表示系統(tǒng)是否有這種外觀,否則使用默認(rèn)的外觀。
現(xiàn)在再讓我們回到Animation類,
Android 中 Animation 資源可以分為兩種:
- Tween Animation 對單個圖像進(jìn)行各種變換(縮放,平移,旋轉(zhuǎn)等)來實現(xiàn)動畫。
- Frame Animation 由一組圖像順序顯示顯示動畫。
Animation 中使用的是Tween Animation,使用的資源為R.anim.fade, R.anim.hold,R.anim.zoom_enter, R.anim.zoom_exit:
第一按鈕:
fade.xml:
1
<?xml version="1.0" encoding="utf-8"?>
2
<!-- Copyright (C) 2007 The Android Open Source Project
3
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7
8
http://www.apache.org/licenses/LICENSE-2.0
9
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
-->
16
17
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
18
android:interpolator="@android:anim/accelerate_interpolator"
19
android:fromAlpha="0.0" android:toAlpha="1.0"
20
android:duration="@android:integer/config_longAnimTime" />
21
hold.xml:
1
<?xml version="1.0" encoding="utf-8"?>
2
<!-- Copyright (C) 2009 The Android Open Source Project
3
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7
8
http://www.apache.org/licenses/LICENSE-2.0
9
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
-->
16
17
<translate xmlns:android="http://schemas.android.com/apk/res/android"
18
android:interpolator="@android:anim/accelerate_interpolator"
19
android:fromXDelta="0" android:toXDelta="0"
20
android:duration="@android:integer/config_longAnimTime" />
21
zoom_enter.xml:
1
<?xml version="1.0" encoding="utf-8"?>
2
<!--
3
/*
4
** Copyright 2009, The Android Open Source Project
5
**
6
** Licensed under the Apache License, Version 2.0 (the "License");
7
** you may not use this file except in compliance with the License.
8
** You may obtain a copy of the License at
9
**
10
** http://www.apache.org/licenses/LICENSE-2.0
11
**
12
** Unless required by applicable law or agreed to in writing, software
13
** distributed under the License is distributed on an "AS IS" BASIS,
14
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
** See the License for the specific language governing permissions and
16
** limitations under the License.
17
*/
18
-->
19
20
<!-- Special window zoom animation: this is the element that enters the screen,
21
it starts at 200% and scales down. Goes with zoom_exit.xml. -->
22
<set xmlns:android="http://schemas.android.com/apk/res/android"
23
android:interpolator="@android:anim/decelerate_interpolator">
24
<scale android:fromXScale="2.0" android:toXScale="1.0"
25
android:fromYScale="2.0" android:toYScale="1.0"
26
android:pivotX="50%p" android:pivotY="50%p"
27
android:duration="@android:integer/config_mediumAnimTime" />
28
</set>
29
zoom_exit.xml:
1
<?xml version="1.0" encoding="utf-8"?>
2
<!--
3
/*
4
** Copyright 2009, The Android Open Source Project
5
**
6
** Licensed under the Apache License, Version 2.0 (the "License");
7
** you may not use this file except in compliance with the License.
8
** You may obtain a copy of the License at
9
**
10
** http://www.apache.org/licenses/LICENSE-2.0
11
**
12
** Unless required by applicable law or agreed to in writing, software
13
** distributed under the License is distributed on an "AS IS" BASIS,
14
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
** See the License for the specific language governing permissions and
16
** limitations under the License.
17
*/
18
-->
19
20
<!-- Special window zoom animation: this is the element that exits the
21
screen, it is forced above the entering element and starts at its
22
normal size (filling the screen) and scales down while fading out.
23
This goes with zoom_enter.xml. -->
24
<set xmlns:android="http://schemas.android.com/apk/res/android"
25
android:interpolator="@android:anim/decelerate_interpolator"
26
android:zAdjustment="top">
27
<scale android:fromXScale="1.0" android:toXScale=".5"
28
android:fromYScale="1.0" android:toYScale=".5"
29
android:pivotX="50%p" android:pivotY="50%p"
30
android:duration="@android:integer/config_mediumAnimTime" />
31
<alpha android:fromAlpha="1.0" android:toAlpha="0"
32
android:duration="@android:integer/config_mediumAnimTime"/>
33
</set>
34
從代碼可以看到Activity Animation到其它Activity Controls1 切換的動畫使用overridePendingTransition 來定義,函數(shù)overridePendingTransition(int enterAnim, int exitAnim) 必須定義在StartActivity(Intent)或是 Activity.finish()之后來定義兩個Activity切換時的動畫,enterAnim 為新Activity出現(xiàn)時動畫效果,exitAnim則定義了當(dāng)前Activity退出時動畫效果。
第三個按鈕和第四個按鈕的動畫分別與第一個按鈕和第二個動畫相同,只不過換了一種實現(xiàn)的方式。利用API16的ActivityOptions類。
通過ActivityOptions設(shè)置動畫轉(zhuǎn)化為Bundle,作為Intent屬性啟動activity。由一個activity的啟動、另一個activity的停止兩組動畫組成。
http://developer.android.com/reference/android/app/ActivityOptions.html
下面三個按鈕都是通過ActivityOptions的三個方法來創(chuàng)建動畫。
最后一個動畫是通過在指定某個地方放入一個新Activity的縮略圖,然后充滿充滿整個屏幕。

View組件顯示的內(nèi)容可以通過cache機(jī)制保存為bitmap, 使用到的api有
void setDrawingCacheEnabled(boolean flag),
Bitmap getDrawingCache(boolean autoScale),
void buildDrawingCache(boolean autoScale),
void destroyDrawingCache()
我們要獲取它的cache先要通過setDrawingCacheEnable方法把cache開啟,然后再調(diào)用getDrawingCache方法就可以獲得view的cache圖片了。buildDrawingCache方法可以不用調(diào)用,因為調(diào)用getDrawingCache方法時,若果cache沒有建立,系統(tǒng)會自動調(diào)用buildDrawingCache方法生成cache。若果要更新cache, 必須要調(diào)用destoryDrawingCache方法把舊的cache銷毀,才能建立新的。
當(dāng)調(diào)用setDrawingCacheEnabled方法設(shè)置為false, 系統(tǒng)也會自動把原來的cache銷毀。
ViewGroup在繪制子view時,而外提供了兩個方法
void setChildrenDrawingCacheEnabled(boolean enabled)
setChildrenDrawnWithCacheEnabled(boolean enabled)
setChildrenDrawingCacheEnabled方法可以使viewgroup里所有的子view開啟cache, setChildrenDrawnWithCacheEnabled使在繪制子view時,若該子view開啟了cache, 則使用它的cache進(jìn)行繪制,從而節(jié)省繪制時間。
獲取cache通常會占用一定的內(nèi)存,所以通常不需要的時候有必要對其進(jìn)行清理,通過destroyDrawingCache或setDrawingCacheEnabled(false)實現(xiàn)。