简体   繁体   English

如何使活动模糊然后随着新活动消失?

[英]How to make an activity blur then disappear with new activity?

I have a slpash screen which has one image I want to make the image or activity blur before the next activity gets called. 我有一个slpash屏幕,其中有一个图像,我想在调用下一个活动之前使图像或活动模糊。

I tried to use fade_in fade_out anim but its not working. 我尝试使用fade_in fade_out动画,但无法正常工作。

Tried code given in this accepted answer : Android Studio fading splash into main 尝试过的代码在此可接受的答案中给出: Android Studio逐渐淡入主屏幕

splashScreen 闪屏

public class SplashScreen extends Activity {

    private Thread mSplashThread;

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_layout);
        final SplashScreen sPlashScreen = this;

        mSplashThread =  new Thread(){
            @Override
            public void run(){
                try {
                    synchronized(this){
                        wait(3000);
                    }
                }
                catch(InterruptedException ex){
                }

                finish();

                Intent intent = new Intent();
                intent.setClass(sPlashScreen,LoginActivity.class);
                startActivity(intent);
                overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
            }
        };

        mSplashThread.start();
    }

    @Override
    public boolean onTouchEvent(MotionEvent evt)
    {
        if(evt.getAction() == MotionEvent.ACTION_DOWN)
        {
            synchronized(mSplashThread){
                mSplashThread.notifyAll();
            }
        }
        return true;
    }
}

Fade_in : 淡入 :

<?xml version="1.0" encoding="utf-8"?>
<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="500" />

Fade_out : 淡出 :

   <?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:fromAlpha="1.0" android:toAlpha="0.0"
    android:fillAfter="true"
    android:duration="500" />

What Can I do for blur animation? 对于模糊动画我该怎么办? I want the slpash activity to look blur before the another activity starts. 我希望slpash活动在另一个活动开始之前看起来模糊。

Please help.Thank you.. 请帮助。谢谢。

If overridePendingTransition doesn't work as you want for fade_in and fade_out. 如果overridePendingTransition无法按您想要的fade_in和fade_out工作。 You can make a workaround. 您可以采取解决方法。 before navigating, make a animation for your app container to Blur, using a animation library like: https://github.com/2359media/EasyAndroidAnimations or https://github.com/daimajia/AndroidViewAnimations And an animation to fade in the content of the next activty, and use activity.overridePendingTransition(NO_ANIMATION, NO_ANIMATION); 导航之前,请使用以下动画库将您的应用容器的动画制作为“模糊”: https : //github.com/2359media/EasyAndroidAnimationshttps://github.com/daimajia/AndroidViewAnimations,然后使用动画淡入内容下一个活动,并使用activity.overridePendingTransition(NO_ANIMATION,NO_ANIMATION);

Note: this is not something I tried, but it should work 注意:这不是我尝试过的方法,但是应该可以

You can add one overlay in splash_layout as shown below to have the dim effect. 您可以如下所示在splash_layout中添加一个叠加层,以产生暗淡的效果。 and make it visible before starting the new activity. 并在开始新活动之前使其可见。

<View
    android:id="@+id/overlay_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#A0000000"
    android:visibility="gone" />

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何模糊对话框活动背景 - how to blur a dialog activity background 你如何在 android 中创建一个按钮来打开一个新的活动,这个活动不仅仅是一个默认活动,它是一个自定义活动 - How do you make a button in android that opens a new activity and this activity is not just a default activity its a custom one Android,如何模糊/玻璃/霜当前活动 - Android, how to blur/glass/frost current activity 如何模糊当前活动,但不模糊菜单信息 - How to blur current activity, but don't blur menu-info 如何制作不透明的活动? - How to make an opaque Activity? 为什么当我开始一项新活动时我的背景消失了? - why does my background disappear when i start a new activity? 如何开始一个新活动并在该活动中启动方法 - How to start a new activity and start a method in that activity 如何使一个活动不回溯到先前的活动 - How to make an activity not backtrack to previous activity 如何让 addSnapshotListener 不启动新活动? 适用于 Java 但不适用于 Kotlin - How to make addSnapshotListener to not start a new activity? Works with Java but not Kotlin Android:如何滑动至右侧屏幕并打开新活动2 - Android: How to make Swipe to the right screen and open a new activity 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM