我有一个显示项目列表的应用程序.我需要在主要活动开始前显示淡出图像.我在onCreate主要活动方法中尝试了类似的东西,我开始了一个动画活动
Intent animationIntent=new Intent(this,AnimationActivity.class);
startActivityForResult(AnimationIntent);
Run Code Online (Sandbox Code Playgroud)
在AnimationActivity.class的onCreate方法中
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);
Run Code Online (Sandbox Code Playgroud)
我的main.xml是
<?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>
Run Code Online (Sandbox Code Playgroud)
这种方法的问题在于它显示了一个动画,但是imageview来了一段时间,主要活动带有幻灯片过渡效果
但我希望我的形象淡出,我的活动应该淡入
任何帮助将不胜感激.提前致谢
Man*_*man 30
基本上,你正在寻找的是一个Splash屏幕,它会显示你的图像,然后淡出.然后主要活动的屏幕淡入.所以你可以做的是为Splash屏幕创建一个活动,然后为你可能想要调用的主要活动创建另一个活动.这将是您的Splash Screen活动.
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);
}
Run Code Online (Sandbox Code Playgroud)
NextActivity是您希望淡入并取而代之的任何活动.对于动画,您需要在资源中名为animate的文件夹中创建两个xml文件.这是splashfadeout.xml文件
<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" />
Run Code Online (Sandbox Code Playgroud)
这将是activityfadein.xml文件
<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" />
Run Code Online (Sandbox Code Playgroud)
这些文件基本上使您的活动淡入淡出
| 归档时间: |
|
| 查看次数: |
15095 次 |
| 最近记录: |