android 使用共享元素转换后,活动刚刚 Flink

o4hqfura  于 12个月前  发布在  Android
关注(0)|答案(5)|浏览(110)

嗨,我正在开发一个应用程序,我使用共享元素过渡动画进入和退出过渡登录和注册活动动画一个imageview和两个textviews,但我的问题是,意见没有动画,而不是在所有当我点击注册按钮的注册活动 Flink 两次,没有动画发生,而且在注册活动的图像损失其形状,所以我不知道我去错了,因为我我在两个活动中给出了相同的转换名称,但问题仍然存在,因此我希望得到一些帮助。

<resources xmlns:tools="http://schemas.android.com/tools">

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowEnableSplitTouch">false</item>
        <item name="android:splitMotionEvents">false</item>

        <!-- Transition -->
        <item name="android:windowContentTransitions" tools:targetApi="21">true</item>
        <item name="android:windowEnterTransition" tools:targetApi="21">@android:transition/fade
        </item>
        <item name="android:windowExitTransition" tools:targetApi="21">@android:transition/fade
        </item>
        <item name="android:windowActivityTransitions">true</item>
        <item name="android:windowSharedElementEnterTransition" tools:targetApi="21">
            @android:transition/move
        </item>
        <item name="android:windowSharedElementExitTransition" tools:targetApi="21">
            @android:transition/move
        </item>
    </style>

</resources>

字符串
我的登录活动

public void gotoregister(View view) {
        Intent intent = new Intent(LoginActivity.this,RegisterActivity.class);
        Pair[] pairs  = new Pair[3];
        pairs[0] = new Pair<View,String>(text_login,getResources().getString(R.string.login_text_transition));
        pairs[1] = new Pair<View,String>(login_page_curve,getResources().getString(R.string.transition_name_signup));
        pairs[2] = new Pair<View,String>(register_text,getResources().getString(R.string.register_text_transition));
        ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation
                (LoginActivity.this,pairs);
        startActivity(intent,optionsCompat.toBundle());
        finish();
        //overridePendingTransition(R.anim.bottom_up,R.anim.bottom_down);

    }

w8biq8rn

w8biq8rn1#

这在我的代码中工作。
styles.xml

<!-- Base application theme. -->
    s<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowDisablePreview">true</item>
    <item name="android:windowEnableSplitTouch">false</item>
    <item name="android:splitMotionEvents">false</item>
    <item name="android:windowAnimationStyle">@style/CustomActivityAnimation</item>
</style>

<style name="AppTheme.NoActionBarMain">
    <item name="windowActionBar">false</item>
    <item name="android:windowDisablePreview">true</item>
    <item name="windowNoTitle">true</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowEnableSplitTouch">false</item>
    <item name="android:splitMotionEvents">false</item>
    <item name="android:colorForeground">@color/foreground_material_light</item>
</style>

字符串
styles.xml(v21)

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:windowEnableSplitTouch">false</item>
    <item name="android:splitMotionEvents">false</item>
</style>

g0czyy6m

g0czyy6m2#

试试这个。

View sharedView = splashLogo;
            String transitionName = getString(R.string.splash_logo_animate);
            if (Build.VERSION.SDK_INT >= 21) {
                ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(SplashscreenActivity.this, sharedView, transitionName);
                startActivity(i, options.toBundle());
                finishAfterTransition();
            }
            else {
                ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(SplashscreenActivity.this, sharedView, transitionName);
                ActivityCompat.startActivity(getApplicationContext(), i, options.toBundle());
                finish();
            }

字符串

elcex8rz

elcex8rz3#

你有没有试过在你的风格主题中使用这些?

<item name="android:windowContentTransitions">true</item>
    <item name="android:windowActivityTransitions">true</item>

字符串

iqjalb3h

iqjalb3h4#

我看到你在开始一个新的transition后完成了当前的Activity。如果你这样完成,进入和退出的transition将丢失。
试着保留LoginActivity,看看它是否有效

kxxlusnw

kxxlusnw5#

为了实现平滑过渡,请按照以下两个步骤操作。

<?xml version="1.0" encoding="utf-8"?>
<transitionSet>
  <changeImageTransform />
  <changeBounds />
  <changeClipBounds />
  <changeTransform />
</transitionSet>

字符串
在findViewById(android.R.id.content).setTransitionName(“userPic”)之后的调用Activity中写入这2行;

getWindow().setSharedElementEnterTransition(TransitionInflater.from(this).inflateTransition(R.transition.image_transform));
getWindow().setSharedElementExitTransition(TransitionInflater.from(this).inflateTransition(R.transition.image_transform));

相关问题