MainActivity
public class MainActivity extends Activity {
TextView Mtv;
Handler handler;
int item=4;
ImageView Mimg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//找控件
Mtv=(TextView) findViewById(R.id.Mtv);
Mimg=(ImageView) findViewById(R.id.Mimg);
//创建动画集合
AnimationSet animationSet=new AnimationSet(true);
//透明度
AlphaAnimation alphaAnimation=new AlphaAnimation(1f, 0.5f);
animationSet.addAnimation(alphaAnimation);
//缩放
ScaleAnimation scaleAnimation=new ScaleAnimation(1f,2f,1f,2f);
animationSet.addAnimation(scaleAnimation);
//旋转
RotateAnimation rotateAnimation=new RotateAnimation(0f,360,0.5f, 0.5f);
animationSet.addAnimation(rotateAnimation);
//平移
TranslateAnimation translateAnimation=new TranslateAnimation(1f, 2f,1f, 2f);
animationSet.addAnimation(translateAnimation);
animationSet.setDuration(3000);
animationSet.setFillAfter(true);
//启动动画
Mimg.startAnimation(animationSet);
//Hanlder倒计时跳转
handler=new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
item--;
if (item==-1) {
Intent intent=new Intent(MainActivity.this,Two.class);
startActivity(intent);
}
handler.postDelayed(this,1000);
Mtv.setText("倒计时:"+item+"秒");
}
},1000);
}
}
Layout布局
<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"
>
<TextView
android:id="@+id/Mtv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="跳转"
android:textSize="20sp"/>
<ImageView
android:id="@+id/Mimg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_centerInParent="true"
/>
</RelativeLayout>