怎么在Android中實現(xiàn)動畫漸隱漸現(xiàn)效果-創(chuàng)新互聯(lián)

這篇文章將為大家詳細(xì)講解有關(guān)怎么在Android中實現(xiàn)動畫漸隱漸現(xiàn)效果,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

創(chuàng)新互聯(lián)主營徐州網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都app軟件開發(fā)公司,徐州h5小程序制作搭建,徐州網(wǎng)站營銷推廣歡迎徐州等地區(qū)企業(yè)咨詢

四種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)漸隱的圖片進行id標(biāo)示。

3)、實現(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;
 
 }
}

關(guān)于怎么在Android中實現(xiàn)動畫漸隱漸現(xiàn)效果就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

文章標(biāo)題:怎么在Android中實現(xiàn)動畫漸隱漸現(xiàn)效果-創(chuàng)新互聯(lián)
本文URL:http://muchs.cn/article40/cddieo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計公司做網(wǎng)站、網(wǎng)站建設(shè)網(wǎng)站排名、企業(yè)網(wǎng)站制作、網(wǎng)站導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設(shè)