Android開啟動畫之漸隱漸現(xiàn)效果
啟動某項(xiàng)程序時我們往往都能看到不同的“開機(jī)動畫”,千變?nèi)f化的動畫也只不過是四種基本動畫衍變美化而成的。
四種android動畫效果:
- alpha 漸變透明度動畫效果
- scale 漸變尺寸伸縮動畫效果
- translate 畫面轉(zhuǎn)換位置移動動畫效果
- rotate 畫面轉(zhuǎn)移旋轉(zhuǎn)動畫效果
最簡單的莫過于漸變透明效果,單單這一種就可完成漸隱漸現(xiàn)的動畫效果(用于漸現(xiàn)漸隱的可以是整個歡迎頁面也可以是歡迎頁面里的一部分):
1)、 在res里新建anim文件夾用來盛放動畫定義的動作文件:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="2000"/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:startOffset="3000"
android:duration="3000"/>
</set>
fromalpha即開始的透明度,toalpha即結(jié)束時的透明度,duration為時間(單位毫秒)。
2)、定義布局文件(layout):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="@+id/welcom_logo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/welcome" />
</LinearLayout>
這里和以往沒有任何不同,只需對要漸現(xiàn)漸隱的圖片進(jìn)行id標(biāo)示。
3)、實(shí)現(xiàn)方法(Activity):
public class WelcomeActivity extends Activity implements AnimationListener {
private ImageView imageView = null;
private Animation alphaAnimation = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
imageView = (ImageView) findViewById(R.id.welcom_logo);
alphaAnimation = AnimationUtils.loadAnimation(this,
R.anim.welcome_alpha);
alphaAnimation.setFillEnabled(true);//啟動Fill保持
alphaAnimation.setFillAfter(true);//設(shè)置動畫的最后一幀是保留在view上的
imageView.setAnimation(alphaAnimation);
alphaAnimation.setAnimationListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_welcome, menu);
return true;
}
@Override
public void onAnimationEnd(Animation animation) {
//動畫結(jié)束時結(jié)束歡迎頁面并跳轉(zhuǎn)到主頁面
Intent intent=new Intent(this,GroupActivity.class);
startActivity(intent);
this.finish();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}
public boolean onKeyDown(int KeyCode,KeyEvent event){
//在歡迎頁面屏蔽BACK鍵
if(KeyCode==KeyEvent.KEYCODE_BACK){
return false;
}
return false;
}
}
歡迎頁面顧名思義只是裝飾作用一閃而過不需要返回鍵進(jìn)行操作。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android隱藏和沉浸式虛擬按鍵NavigationBar的實(shí)現(xiàn)方法
今天小編就為大家分享一篇Android隱藏和沉浸式虛擬按鍵NavigationBar的實(shí)現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-07-07
Android編程實(shí)現(xiàn)的手寫板和涂鴉功能
這篇文章主要介紹了Android編程實(shí)現(xiàn)的手寫板和涂鴉功能,涉及Android界面布局及圖形繪制功能相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-01-01
Android基礎(chǔ)入門之dataBinding的簡單使用教程
DataBinding 是谷歌官方發(fā)布的一個框架,顧名思義即為數(shù)據(jù)綁定,下面這篇文章主要給大家介紹了關(guān)于Android基礎(chǔ)入門之dataBinding的簡單使用,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-06-06
Android實(shí)現(xiàn)PDF預(yù)覽打印功能
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)PDF預(yù)覽打印功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-12-12
Android開發(fā)中實(shí)現(xiàn)應(yīng)用的前后臺切換效果
這篇文章主要介紹了Android開發(fā)中實(shí)現(xiàn)應(yīng)用的前后臺切換效果的方法,文章最后還附帶了監(jiān)聽程序是否進(jìn)入后臺的判斷方法,需要的朋友可以參考下2016-02-02
Flutter 用自定義轉(zhuǎn)場動畫實(shí)現(xiàn)頁面切換
本篇介紹了 fluro 導(dǎo)航到其他頁面的自定義轉(zhuǎn)場動畫實(shí)現(xiàn),F(xiàn)lutter本身提供了不少預(yù)定義的轉(zhuǎn)場動畫,可以通過 transitionBuilder 參數(shù)設(shè)計多種多樣的轉(zhuǎn)場動畫,也可以通過自定義的 AnimatedWidget實(shí)現(xiàn)個性化的轉(zhuǎn)場動畫效果。2021-06-06

