android项目【新闻】项目实战(一):开发启动图并实现动画效果
来源:互联网 发布:php中while的用法 编辑:程序博客网 时间:2024/05/21 06:42
一:创建android项目,结构如图
二:添加启动图的SplashActivity和布局文件
布局文件代码:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/splash_root" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/splash_bg_newyear" tools:context="com.jingtong.hefeinews.SplashActivity"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:src="@drawable/splash_sheep_newyear"/></RelativeLayout>
SplashActivity代码如下:
public class SplashActivity extends AppCompatActivity { public static final String START_MAIN = "start_main"; private RelativeLayout splash_root; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); splash_root = (RelativeLayout) findViewById(R.id.splash_root); //渐变动画 AlphaAnimation alphaAnimation = new AlphaAnimation(0,1); //设置持续播放时间 alphaAnimation.setDuration(500); alphaAnimation.setFillAfter(true); //缩放动画 ScaleAnimation scaleAnimation = new ScaleAnimation(0,1,0,1,ScaleAnimation.RELATIVE_TO_SELF,0.5f,ScaleAnimation.RELATIVE_TO_SELF,0.5f); scaleAnimation.setDuration(500); scaleAnimation.setFillAfter(true); //旋转动画 RotateAnimation rotateAnimation = new RotateAnimation(0,360,RotateAnimation.RELATIVE_TO_SELF,0.5f,RotateAnimation.RELATIVE_TO_SELF,0.5f); rotateAnimation.setDuration(500); rotateAnimation.setFillAfter(true); AnimationSet set = new AnimationSet(false); set.addAnimation(alphaAnimation); set.addAnimation(scaleAnimation); set.addAnimation(rotateAnimation); set.setDuration(2000); splash_root.startAnimation(set); set.setAnimationListener(new MyAnimationListenner()); } //动画监听 class MyAnimationListenner implements Animation.AnimationListener{ @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { boolean isStartMain = CacheUtils.getBoolean(SplashActivity.this,START_MAIN); if (isStartMain){ //如果进入过主页面,直接进入主页面 }else { //如果没有进入过主页面,进入向导界面 Intent intent = new Intent(SplashActivity.this,GuideActivity.class); startActivity(intent); } finish(); Toast.makeText(SplashActivity.this, "播放完成", Toast.LENGTH_SHORT).show(); } @Override public void onAnimationRepeat(Animation animation) { } }}
动态效果图:
阅读全文
0 0
- android项目【新闻】项目实战(一):开发启动图并实现动画效果
- android实战项目二实现画板效果
- iOS项目开发实战——视图动画效果
- 项目实战No5 动画效果 占位文字
- 练习项目 一款新闻app的开发 (一) : 欢迎界面开发(属性动画的运用)
- iOS项目开发实战——实现视图切换动画
- Android开发----实战项目
- android小项目之新闻客户端一
- android小项目之新闻客户端一
- Android项目实战之仿腾讯新闻客户端的部分功能实现
- 安卓新闻客户端实战(一):项目简介
- 开源项目推荐(3):Android UI Patterns 实现各种UI效果,含动画
- Apicloud开发新闻类App实战项目-老孟编程
- 13讲项目实战内页滚动图效果实现
- Android开发(25)--framebyframe帧动画并实现启动界面到主界面的跳转
- 项目中的动画效果,gif实现
- Android项目开发实战:倒计时
- Android项目开发实战:倒计时
- Apache/Tomcat/JBOSS/Nginx区别
- 35 个 Java 代码性能优化总结
- PhotoPicker的深度使用 自定义PhotoPicker 更改PhotoPicker默认黑色背景
- nba
- 关于View Measure 的 MeasureSpec的mode 思考
- android项目【新闻】项目实战(一):开发启动图并实现动画效果
- 文件批量顺序重命名
- jdk下载及安装配置
- 1.通过tcp从daytime服务器获取时间
- Mysql 高性能设计
- 递归的函数 记忆化搜索
- Redis.config配置详解
- js中数组与数组,数组与对象,对象与对象间的合并
- mpu6050加速度角速度融合为四元数计算函数的说明