我有一个SearchView
坐在左上角的一个活动中,它位于另一个活动的右下角。
<SearchView
android:id="@+id/searchView"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_alignParentStart="true"
android:layout_below="@+id/toolbar_main"
android:clickable="false"
android:focusable="false"
android:iconifiedByDefault="false"
android:queryHint="Search a product"
android:transitionName="search">
和目标活动
<SearchView
android:id="@+id/searchView"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:clickable="false"
android:focusable="false"
android:iconifiedByDefault="false"
android:queryHint="Search a product"
android:transitionName="search" />
在第一项活动中,我使用以下代码,目标活动为SearchableActivity
View mySearch = findViewById(R.id.searchView);
ActivityOptions options = ActivityOptions
.makeSceneTransitionAnimation(this, mySearch, "search");
intent = new Intent(this, SearchableActivity.class);
startActivity(intent,options.toBundle());
我认为实现起来很简单:)但是没有动画,它只是出现在底部。我不确定问题出在哪里?有什么想法吗?
更新: 我尝试手动启用动画:
// inside your activity (if you did not enable transitions in your theme)
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
// set an enter transition
getWindow().setEnterTransition(new Explode());
// set an exit transition
getWindow().setExitTransition(new Explode());
加上风格:
<item name="android:windowContentTransitions">true</item>
并尝试使用ImageView
对象,但由于某种原因它无效...
答案 0 :(得分:1)
来自codepath's guide on shared element transitions:确保您已在android:windowContentTransitions
中启用styles.xml
:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:windowContentTransitions">true</item>
...
</style>