论SplashActivity(一)
2015-12-12 11:12
211 查看
对于这个相信做过项目的都懂,那就让不太懂的了解了解吧
要设置Splash页面,首先想到的是,如何设置全屏问题,直接上代码,下面有两种方法可以使用The first method
在清单文件(AndroidManifest.xml)中设置
<activity android:name=".SplashActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > </activity>
The second method
在代码(code)中实现
public class SplashActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // No Titlebar this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_splash); // Full Screen getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } }
谨记
(this.requestWindowFeature(Window.FEATURE_NO_TITLE);)
必须在(setContentView(R.layout.activity_splash);)之前
布局文件activity_splash.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/rl_root" tools:context="com.example.admin.zhbj.SplashActivity"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@mipmap/splash_horse_newyear"/> </RelativeLayout>
接下来(Following)我们要处理的是设置SplashActivity的动画效果
单个动画设置
RelativeLayout rlRoot; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // No Titlebar this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_splash); // Full Screen getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); rlRoot = (RelativeLayout) findViewById(R.id.rl_root); startAnim(); } /** * 开启动画 */ private void startAnim() { //旋转动画 RotateAnimation rotate = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotate.setDuration(5000);//动画时间 rotate.setFillAfter(true);//保持动画状态 rlRoot.startAnimation(rotate); }
对于多个动画(animation)问题code如下:
/** * 开启动画 */ private void startAnim() { //动画集合 AnimationSet set = new AnimationSet(false); //旋转动画 RotateAnimation rotate = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotate.setDuration(5000);//动画时间 rotate.setFillAfter(true);//保持动画状态 //缩放动画 ScaleAnimation scale = new ScaleAnimation(0,1,0,1,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); scale.setDuration(5000);//动画时间 scale.setFillAfter(true);//保持动画状态 //渐变动画 AlphaAnimation alp = new AlphaAnimation(0,1); alp.setDuration(5000);//动画时间 alp.setFillAfter(true);//保持动画状态 set.addAnimation(rotate); set.addAnimation(scale); set.addAnimation(alp); rlRoot.startAnimation(set); }
动画监听的设置
//设置动画监听 set.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } //动画结束 @Override public void onAnimationEnd(Animation animation) { startActivity(new Intent(SplashActivity.this, GuideActivity.class)); finish(); } @Override public void onAnimationRepeat(Animation animation) { } });
传承者(Inheritors)欢迎各位纠正错误,评论,吐槽!!!
相关文章推荐
- Java中对象的类型判断
- GridControl的模糊查询
- hadoop学习日志
- php并发
- C语言总结
- MySQL Binlog Server(5.6)
- nginx location匹配优先级
- 视频图像处理项目伊始
- java中的this与super的区别
- linux ubuntu中修改终端的设备名称(计算机名称)
- varchar和text区别
- nodejs初探(三)实现一个简单的socket交互
- OpenOffice菜单方块乱码问题
- TextView 文字描边
- Updating classpath container 提示更新屏蔽
- springmvc 接收json对象的两种方式
- 单链表
- Java并发包中的同步队列SynchronousQueue实现原理
- flappy bird
- 刷过一题之阶乘的K位数