這篇文章將為大家詳細(xì)講解有關(guān)怎么在Android中實(shí)現(xiàn)動畫漸隱漸現(xiàn)效果,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了萬寧免費(fèi)建站歡迎大家使用!
四種android動畫效果:
alpha 漸變透明度動畫效果
scale 漸變尺寸伸縮動畫效果
translate 畫面轉(zhuǎn)換位置移動動畫效果
rotate 畫面轉(zhuǎn)移旋轉(zhuǎn)動畫效果
最簡單的莫過于漸變透明效果,單單這一種就可完成漸隱漸現(xiàn)的動畫效果(用于漸現(xiàn)漸隱的可以是整個(gè)歡迎頁面也可以是歡迎頁面里的一部分):
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é)束時(shí)的透明度,duration為時(shí)間(單位毫秒)。
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é)束時(shí)結(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; } }
關(guān)于怎么在Android中實(shí)現(xiàn)動畫漸隱漸現(xiàn)效果就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
分享標(biāo)題:怎么在Android中實(shí)現(xiàn)動畫漸隱漸現(xiàn)效果
標(biāo)題路徑:http://chinadenli.net/article42/gepiec.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)、企業(yè)網(wǎng)站制作、Google、網(wǎng)站制作、網(wǎng)站內(nèi)鏈、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)