简体   繁体   English

共享元素过渡不起作用,黑屏

[英]Shared element transitions not working, blank screen

My transitions aren't working, the first image view shows the drawable but upon running animation it just ends with a white screen. 我的过渡效果不佳,第一个图像视图显示了可绘制对象,但是在运行动画时,它仅以白色屏幕结尾。 Not sure what I'm missing. 不知道我在想什么。

Main Layout 主要布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
    android:id="@+id/main_image"
    android:transitionName="@string/transition_string"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:src="@drawable/image"/>
</RelativeLayout>

Second Activity Layout 第二活动布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
    android:id="@+id/second_image"
    android:transitionName="@string/transition_string"
    android:layout_width="match_parent"
    android:layout_height="300dp"/>
</RelativeLayout>

Main Activity 主要活动

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.main_image).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                animate();
            }
        });
    }

    public void animate() {
        Intent intent = new Intent(this, SecondActivity.class);
        String transitionName = getString(R.string.transition_string);
        View viewStart = findViewById(R.id.main_image);
        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, viewStart, transitionName);
        ActivityCompat.startActivity(this, intent, options.toBundle());
    }
}

Second Activity 第二次活动

public class SecondActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
    }
}

Style 样式

<!-- 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:windowContentTransitions">true</item>
</style>

Add src to second_image, such as; 将src添加到second_image中,例如;

<ImageView
android:id="@+id/second_image"
android:transitionName="@string/transition_string"
android:layout_width="match_parent"
android:layout_height="300dp"
android:src="@drawable/image"/>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM