我的过渡不起作用,第一个图像视图显示可绘制但在运行动画时它只是以白色屏幕结束。不确定我错过了什么。
主要布局
<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>
第二个活动布局
<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>
主要活动
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());
}
}
第二项活动
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>
答案 0 :(得分:2)
将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"/>