案例打开QQ 1.5 秒后进入界面 :
首先:
创建avtivity_welcome.xml 布局
添加个<ImageView> 代码如下:
< LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<!-- 添加图片 -->
<ImageView
android:id="@+id/welcomeImg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/qqwcom"/>
</LinearLayout>
然后 创建WelcomeActivity 继承 activity 实现 AnimationListener
代码如下:
public class WelcomeActivity extends AppCompatActivity implements Animation.AnimationListener {
//声名 ImageView id
private ImageView welcomeImg;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_weleco_m);
welcomeImg = (ImageView) findViewById(R.id.welcomeImg);
//设置动画时间 结束 后跳转到指定页面
final Intent it = new Intent(this, MainActivity.class); //你要转向的Activity
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
startActivity(it); //执行
}
};
timer.schedule(task, 1500); //1.5秒后跳转
}
@Override
public void onAnimationStart (Animation animation) {
}
@Override
public void onAnimationEnd (Animation animation) {
}
@Override
public void onAnimationRepeat (Animation animation) {
}
}