在android中使用动画的两个活动之间的黑色屏幕(Black screen between two activity using animation in android)

编程入门 行业动态 更新时间:2024-10-21 18:36:19
在android中使用动画的两个活动之间的黑色屏幕(Black screen between two activity using animation in android)

我正在使用Apis的幻灯片来展示两个活动之间的滑入和滑出。 但是当我从一个活动跳到另一个活动时,出现一个黑屏。

滑左

<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" > <translate android:duration="300" android:fromXDelta="100%p" android:toXDelta="0" /> </set>

滑右对齐

<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" > <translate android:duration="300" android:fromXDelta="-100%p" android:toXDelta="0" /> </set>

从一个活动跳转到另一个活动: -

Button button1 = (Button) findViewById(R.id.Button01); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { startActivity(new Intent(getApplicationContext(), SecondView.class)); overridePendingTransition(R.anim.slide_left, R.anim.slide_right);

});

为什么这个黑屏出现在两个活动之间。

I am using Apis 's deme for slide-in and slide-out between two activity. But when I jump from one activity to another a black screen is appearing.

Slide-Left-

<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" > <translate android:duration="300" android:fromXDelta="100%p" android:toXDelta="0" /> </set>

Slide-Right-

<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" > <translate android:duration="300" android:fromXDelta="-100%p" android:toXDelta="0" /> </set>

To Jump from one activity to another:-

Button button1 = (Button) findViewById(R.id.Button01); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { startActivity(new Intent(getApplicationContext(), SecondView.class)); overridePendingTransition(R.anim.slide_left, R.anim.slide_right);

});

Why is this black screen is appearing between two activity.

最满意答案

你的第一个xml应该是这样的:

<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" > <translate android:duration="300" android:fromXDelta="0" android:toXDelta="100%p" /> </set>

fromXDelta是在动画开始处应用的水平转换。 将它设置为“100%p”会使动画开始时第一个活动刚刚移出屏幕,因此出现空白屏幕。

对函数overridePendingTransition(int, int)的调用应该是这样的:

overridePendingTransition(R.anim.slide_right, R.anim.slide_left);

第一个参数确定第二个活动使用的过渡动画。 另外,这两个动画可以更正确地命名为slide_out_to_right和slide_in_from_left,因为实际上它们都向右滑动。

Your first xml should be like:

<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" > <translate android:duration="300" android:fromXDelta="0" android:toXDelta="100%p" /> </set>

fromXDelta is the horizontal translation applied at the beginning of the animation. Setting it to "100%p" makes the first activity shift just right out of the screen at the inception of the animation, hence the blank screen.

The call to the function overridePendingTransition(int, int) should be like this:

overridePendingTransition(R.anim.slide_right, R.anim.slide_left);

The first argument determines the transition animation used by the second activity. Also the two animations can be more properly named as slide_out_to_right and slide_in_from_left, since in fact they all slide to the right.

更多推荐

android,活动,activity,电脑培训,计算机培训,IT培训"/> <meta name="descripti

本文发布于:2023-07-04 17:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026908.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:屏幕   黑色   两个   动画   android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!