我需要在第5次活动之前从第1次活动转移到第2次活动,然后再转到第2次活动。我的第一个活动包含一个使用以下代码旋转的图像 -
ImageForRotation.StartAnimation(loadedImage)
第二个活动是登录页面。这是我的代码 -
base.OnCreate(bundle);
SetContentView(Resource.Layout.SplashScreen);
ImageView ImageForRotation = FindViewById < ImageView > (Resource.Id.imageForRotation);
var loadedImage = AnimationUtils.LoadAnimation(this, Resource.Animation.SplashScreenImageRotation);
ImageForRotation.StartAnimation(loadedImage);
//here the code for 5 second wait time which i don't know
StartActivity(typeof(LoginScreen)); //second activity
答案 0 :(得分:2)
像这样,这是你的第一个活动
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NextActivity();
}
public void NextActivity()
{
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
Intent mainIntent = new Intent(MainActivity.this,Main2Activity.class);
MainActivity.this.startActivity(mainIntent);
MainActivity.this.finish();
}
}, 5000);
}
答案 1 :(得分:0)
//Wait a number of milliseconds. There are 1000 milliseconds in a second.
System.Threading.Thread.Sleep(5000);
//Save time by using System.Threading;
using System.Threading;
Thread.Sleep(5000);
答案 2 :(得分:0)
我不确定你为什么要等待5秒,但是如果你想在完成动画后启动 LoginScreen ,那么你可以通过 setAnimationListener 来实现这一点方法
以下是有关它的详细信息:
public void setAnimationListener(Animation.AnimationListener listener)
它将动画侦听器绑定到此动画。动画侦听器会通知动画事件,例如动画结束或动画重复。
参数:
侦听器 - 要通知的动画侦听器
答案 3 :(得分:0)
SetContentView(Resource.Layout.SplashScreen);
ImageView ImageForRotation = FindViewById<ImageView>(Resource.Id.imageForRotation);
var loadedImage = AnimationUtils.LoadAnimation(this,Resource.Animation.SplashScreenImageRotation);
ImageForRotation.StartAnimation(loadedImage);
System.Threading.Thread.Sleep(5000);
StartActivity(typeof(LoginScreen)); //second activity
答案 4 :(得分:0)
创建处理程序以在特定时间间隔(例如5000毫秒)之后切换到下一个活动
new Handler().postDelayed(new Runnable() {
/*
* Showing your animation screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
@Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(CurrentScreen.this, NextActivity.class);
startActivity(i);
// close this activity
finish();
}
}, 5000);
在添加处理程序之前编写动画代码。