如何在Android中实现动画渐隐渐现效果

发布时间:2022-04-19 11:05:29 作者:iii
来源:亿速云 阅读:164

本篇内容主要讲解“如何在Android中实现动画渐隐渐现效果”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何在Android中实现动画渐隐渐现效果”吧!

四种android动画效果:

最简单的莫过于渐变透明效果,单单这一种就可完成渐隐渐现的动画效果(用于渐现渐隐的可以是整个欢迎页面也可以是欢迎页面里的一部分):

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即结束时的透明度,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>

这里和以往没有任何不同,只需对要渐现渐隐的图片进行id标示。

3)、实现方法(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);//设置动画的最后一帧是保留在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) {
 //动画结束时结束欢迎页面并跳转到主页面
 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;
 
 }
}

到此,相信大家对“如何在Android中实现动画渐隐渐现效果”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. Unity如何实现UI渐隐渐显效果
  2. js如何实现轮播图之渐隐渐现版

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android

上一篇:react的dnd怎么用

下一篇:如何在android中设置webview的定位权限

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》