【问题标题】:Flickering(Blinking) screen when using Shared elements animation to change between activities使用共享元素动画在活动之间切换时闪烁(闪烁)屏幕
【发布时间】:2018-01-05 12:38:25
【问题描述】:

我正在开发一个 Android 应用程序,并在启动屏幕活动和我的登录活动之间使用共享元素转换。当过渡发生时,我可以看到我的手机、应用程序和所有东西的背景,我可以从我的应用程序中看到的唯一东西是徽标动画,其他所有东西都消失了。

这是我的代码:

启动画面(起源)

<LinearLayout
        android:id="@+id/meofat_logo"
        android:layout_width="86dp"
        android:layout_height="86dp"
        android:layout_gravity="center"
        android:background="@drawable/meofat_logo"
        android:orientation="vertical"
        android:layout_marginTop="210dp"
        android:elevation="24dp"
        android:transitionName="logo"/>
    <LinearLayout
        android:id="@+id/meofat_tipo"
        android:layout_width="160dp"
        android:layout_height="50dp"
        android:background="@drawable/meofat_tipo"
        android:layout_gravity="center"
        android:elevation="24dp"
        android:transitionName="tipo"/>

登录屏幕(目的地)

<LinearLayout
            android:id="@+id/meofat_logo"
            android:layout_width="58dp"
            android:layout_height="58dp"
            android:layout_gravity="center"
            android:background="@drawable/meofat_logo"
            android:orientation="vertical"
            android:layout_marginTop="80dp"
            android:elevation="24dp"
            android:transitionName="logo"/>

        <LinearLayout
            android:id="@+id/meofat_tipo"
            android:layout_width="106dp"
            android:layout_height="33dp"
            android:background="@drawable/meofat_tipo"
            android:layout_gravity="center"
            android:elevation="24dp"
            android:transitionName="tipo"/>

闪屏代码:

public class RedirectActivity extends Activity {
    private static int SPLASH_TIME_OUT = 2000;
    LinearLayout logo,tipo;
    Animation upToDown;
    Animation downToUp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.activity_redirect);

        logo = (LinearLayout) findViewById(R.id.meofat_logo);
        tipo = (LinearLayout) findViewById(R.id.meofat_tipo);
        upToDown = AnimationUtils.loadAnimation(this,R.anim.uptodown);
        logo.setAnimation(upToDown);
        downToUp = AnimationUtils.loadAnimation(this,R.anim.downtoup);
        tipo.setAnimation(downToUp);




        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                MEOFatSession session = new MEOFatSession(RedirectActivity.this);

                if (session.isLoggedIn()){
                    Intent goToMeasurement = new Intent(RedirectActivity.this,
                            MeasurementActivity.class);
                    RetrofitInitializer.getInstance().addCredentials(session.getCredentials());
                    startActivity(goToMeasurement);
                    finish();
                } else {
                    Intent goToLogin = new Intent(RedirectActivity.this,
                            LoginActivity.class);
                    ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.
                            makeSceneTransitionAnimation(RedirectActivity.this,findViewById(R.id.meofat_logo),
                                    "logo");
                    startActivity(goToLogin,  optionsCompat.toBundle());
                    finish();
                }

            }
        },SPLASH_TIME_OUT);


    }
}

一个试图说明问题的 gif。

https://giphy.com/gifs/d1G6hKgTAsX5hOo0

【问题讨论】:

  • 请张贴动画xml
  • 考虑到活动 1 和 2 中的位置,我只是使用标准的“自动”动画进行过渡。“topToDown”和“DownToTop”效果很好。
  • 我想知道这是否与我在徽标和提示上使用线性布局而不是图像这一事实有关。

标签: android android-layout android-animation


【解决方案1】:

删除 finish() 方法解决了这个问题。显然它会在动画期间破坏活动,导致它消失。

【讨论】:

    【解决方案2】:

    就像@GaboSampaio 说的,finish() 导致了闪烁。你可以推迟它:

    Handler handler = new Handler();
    handler.postDelayed(this::finish, 1000);
    

    【讨论】:

    • 把你的名字改成 Life Saver。谢谢
    【解决方案3】:
    Intent goToLogin = new Intent(RedirectActivity.this, LoginActivity.class);
    
    ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(
        RedirectActivity.this,
    
        // Now we provide a list of Pair items which contain the view we can transitioning
        // from, and the name of the view it is transitioning to, in the launched activity
        new Pair<View, String>(findViewById(R.id.logo_splash),
        "tipo"));
    
    ActivityCompat.startActivity(RedirectActivity.this, intent, activityOptions.toBundle());
    

    【讨论】:

    • 动画本身可以工作,你的方法仍然有同样的问题。过渡时,除了徽标动画外,其他一切都消失了。
    • 移除finish();
    • alireza silsepor 你介意在单独的回复中添加它,以便我可以投票作为正确答案吗?
    猜你喜欢
    • 1970-01-01
    • 2015-04-06
    • 1970-01-01
    • 1970-01-01
    • 2014-08-02
    • 1970-01-01
    • 2015-04-18
    • 2015-03-08
    • 1970-01-01
    相关资源
    最近更新 更多