倒计时效果demo

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/sanlei1616/article/details/41545305
在主activity上三秒倒计时,同时使主activity半透明不可用。我们启动一个dialog类型的activity。
倒计时使用imageview动画,逐渐放大。 在一张图片动画结束后,放下一张图片动画。最后进入其他界面。
1、启动dialog类型的activity
Intent intent = new Intent();
intent.setClass(MainActivity.this, DialogReady.class);
startActivity(intent);
2、DialogReady.java
public class DialogReady extends Activity {
private ImageView mImageViewReady = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_ready);

this.setFinishOnTouchOutside(false);
this.getWindow().getDecorView().setBackgroundColor(android.R.color.transparent);
mImageViewReady = (ImageView)findViewById(R.id.n_ready);
showReadyPicture3();
}

private void showReadyPicture3(){
final ScaleAnimation animation =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f, 
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
animation.setDuration(1000);
mImageViewReady.setImageDrawable(getResources().getDrawable(R.drawable.n3));
mImageViewReady.setAnimation(animation); 
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
showReadyPicture2();
}
});
}
private void showReadyPicture2(){
final ScaleAnimation animation =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f, 
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
animation.setDuration(1000);
mImageViewReady.setImageDrawable(getResources().getDrawable(R.drawable.n2));
mImageViewReady.setAnimation(animation); 
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
showReadyPicture1();
}
});
}
private void showReadyPicture1(){
final ScaleAnimation animation =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f, 
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
animation.setDuration(1000);
mImageViewReady.setImageDrawable(getResources().getDrawable(R.drawable.n1));
mImageViewReady.setAnimation(animation); 

animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
Intent intent = new Intent();
intent.setClass(DialogReady.this, L2048Activity.class);
startActivity(intent);
DialogReady.this.finish();
}
});

}
@Override    
//屏蔽back键
public boolean onKeyDown(int keyCode, KeyEvent event) {  
if(keyCode == KeyEvent.KEYCODE_BACK){      
return  true;
}  
return  super.onKeyDown(keyCode, event);     

}
3、activity_ready.xml
<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:background="@android:color/transparent"
   >
<ImageView 
        android:id="@+id/n_ready"
        android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/n1"
    android:visibility="visible"
    android:scaleType="fitXY" 
    android:background="@android:color/transparent"
     />
    
    
    </RelativeLayout>
展开阅读全文

没有更多推荐了,返回首页