我有一个显示的项目列表中的应用程序。我需要的主要活动开始前,显示淡出图像。 我想类似的东西 在主要活动的onCreate方法,我开始 像一个动画活动
I have a application which shows list of items. i need to display a fadeout image before start of main activity. i tried something like that in onCreate method of main activity i started one animation activity like
Intent animationIntent=new Intent(this,AnimationActivity.class);
startActivityForResult(AnimationIntent);
在AnimationActivity.class的onCreate方法
in onCreate method of AnimationActivity.class
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView introanim = (ImageView) findViewById(R.id.imgView);
AnimationSet StoryAnimation = (AnimationSet)AnimationUtils.
loadAnimation(this, R.anim.alphanim);
StoryAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
AnimationSubActivity.this.finish();
}
@Override
public void onAnimationEnd(Animation animation) {
AnimationSubActivity.this.finish();
}
});
introanim.clearAnimation();
introanim.startAnimation(StoryAnimation);
和我的main.xml是
and my main.xml is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/imgView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/icon"
/>
</LinearLayout>
问题这种方法是,它显示amimation但ImageView的走到屏幕一段时间,主要活动自带的幻灯片过渡效果
problem with this approach is that it display an amimation but imageview come to screen for a while and main activity comes with slide transition effect
但我想我的图像消失了,我的行为应该淡出
but i want i image fade out and my activity should fade in
任何帮助将AP preciated。在此先感谢
any help will be appreciated. Thanks in advance
推荐答案
基本上,你要找的是一个闪屏,显示您的图片,然后淡出。主要活动的屏幕,然后消失。所以你可以做的是创建一个活动的启动画面,然后另外一个你可能想要呼叫的主要活动。这将是您的闪屏的活动。
Basically, what you're looking for is a Splash screen which shows your image and then fades out. A main activity's screen then fades in. So what you could do is create an activity for the Splash screen and then another one for the main activity you might want to call. This would be your Splash Screen activity.
public class SplashScreen extends Activity {
private static final int SPLASH_DISPLAY_TIME = 4000; // splash screen delay time
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent();
intent.setClass(Splash.this, NextActivity.class);
Splash.this.startActivity(intent);
Splash.this.finish();
// transition from splash to main menu
overridePendingTransition(R.animate.activityfadein,
R.animate.splashfadeout);
}
}, SPLASH_DISPLAY_TIME);
}
NextActivity是要褪色的,并取代它的任何活动。对于动画,你需要在你的资源创建一个文件夹,名为有生两个XML文件。 这里是splashfadeout.xml文件
NextActivity is any activity that you want to fade in and take its place. For the animations you would need to create the two xml files in a folder called animate in your resources. Here is the splashfadeout.xml file
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:zAdjustment="top" android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="4000" />
这将是activityfadein.xml文件
This would be the activityfadein.xml file
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2000" />
这些文件基本上是让你的活动淡入淡出
These files basically make your activities fade in and out
相关推荐
最新文章