本篇內(nèi)容主要講解“如何在Android中實(shí)現(xiàn)動(dòng)畫漸隱漸現(xiàn)效果”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“如何在Android中實(shí)現(xiàn)動(dòng)畫漸隱漸現(xiàn)效果”吧!
四種android動(dòng)畫效果:
alpha 漸變透明度動(dòng)畫效果
scale 漸變尺寸伸縮動(dòng)畫效果
translate 畫面轉(zhuǎn)換位置移動(dòng)動(dòng)畫效果
rotate 畫面轉(zhuǎn)移旋轉(zhuǎn)動(dòng)畫效果
最簡(jiǎn)單的莫過(guò)于漸變透明效果,單單這一種就可完成漸隱漸現(xiàn)的動(dòng)畫效果(用于漸現(xiàn)漸隱的可以是整個(gè)歡迎頁(yè)面也可以是歡迎頁(yè)面里的一部分):
1)、 在res里新建anim文件夾用來(lái)盛放動(dòng)畫定義的動(dòng)作文件:
fromalpha即開(kāi)始的透明度,toalpha即結(jié)束時(shí)的透明度,duration為時(shí)間(單位毫秒)。
2)、定義布局文件(layout):
這里和以往沒(méi)有任何不同,只需對(duì)要漸現(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);//啟動(dòng)Fill保持 alphaAnimation.setFillAfter(true);//設(shè)置動(dòng)畫的最后一幀是保留在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) { //動(dòng)畫結(jié)束時(shí)結(jié)束歡迎頁(yè)面并跳轉(zhuǎn)到主頁(yè)面 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){ //在歡迎頁(yè)面屏蔽BACK鍵 if(KeyCode==KeyEvent.KEYCODE_BACK){ return false; } return false; } }
到此,相信大家對(duì)“如何在Android中實(shí)現(xiàn)動(dòng)畫漸隱漸現(xiàn)效果”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)建站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!