該標(biāo)簽用于指定屏幕內(nèi)的焦點(diǎn)View。
例如我們點(diǎn)擊tab鍵或enter鍵焦點(diǎn)自動(dòng)進(jìn)入下一個(gè)輸入框
用法: 將標(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)自帶的一個(gè)外觀,
?表示系統(tǒng)是否有這種外觀,否則使用默認(rèn)的外觀。
現(xiàn)在再讓我們回到Animation類,
Android 中 Animation 資源可以分為兩種:
- Tween Animation 對(duì)單個(gè)圖像進(jìn)行各種變換(縮放,平移,旋轉(zhuǎn)等)來(lái)實(shí)現(xiàn)動(dòng)畫。
- Frame Animation 由一組圖像順序顯示顯示動(dòng)畫。
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 切換的動(dòng)畫使用overridePendingTransition 來(lái)定義,函數(shù)overridePendingTransition(int enterAnim, int exitAnim) 必須定義在StartActivity(Intent)或是 Activity.finish()之后來(lái)定義兩個(gè)Activity切換時(shí)的動(dòng)畫,enterAnim 為新Activity出現(xiàn)時(shí)動(dòng)畫效果,exitAnim則定義了當(dāng)前Activity退出時(shí)動(dòng)畫效果。
第三個(gè)按鈕和第四個(gè)按鈕的動(dòng)畫分別與第一個(gè)按鈕和第二個(gè)動(dòng)畫相同,只不過(guò)換了一種實(shí)現(xiàn)的方式。利用API16的ActivityOptions類。
通過(guò)ActivityOptions設(shè)置動(dòng)畫轉(zhuǎn)化為Bundle,作為Intent屬性啟動(dòng)activity。由一個(gè)activity的啟動(dòng)、另一個(gè)activity的停止兩組動(dòng)畫組成。
http://developer.android.com/reference/android/app/ActivityOptions.html
下面三個(gè)按鈕都是通過(guò)ActivityOptions的三個(gè)方法來(lái)創(chuàng)建動(dòng)畫。
最后一個(gè)動(dòng)畫是通過(guò)在指定某個(gè)地方放入一個(gè)新Activity的縮略圖,然后充滿充滿整個(gè)屏幕。

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