gpt4 book ai didi

java - 共享元素转换不起作用,黑屏

转载 作者:行者123 更新时间:2023-12-02 03:16:09 28 4
gpt4 key购买 nike

我的转换不起作用,第一个 ImageView 显示了可绘制对象,但在运行动画时它只是以白屏结束。不确定我错过了什么。

主要布局

<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>

第二个 Activity 布局

<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>

主要 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());
}
}

第二个 Activity

public class SecondActivity extends AppCompatActivity {

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

风格

<!-- 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>

最佳答案

在second_image中添加src,如;

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

关于java - 共享元素转换不起作用,黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40268550/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com