Joh*_*uer 1 android transition android-transitions android-cardview android-5.0-lollipop
我想用这里解释的共享元素创建活动转换.
我希望左侧的列表项转换为右侧突出显示的框.

嗯,这很好用,但不幸的是退出转换根本不起作用.从第二次活动回来后,我得到了这个:

CardView只是保持原样,不会在任何地方缩放或转换.过了一会儿,它消失了.
我认为退出转换将是向后转换,但这似乎不是这种情况.如何让CardView转换回左侧的ListItem?
这是我目前的代码:
在第一个Activity的OnItemClickListener中
Intent intent = new Intent(context, DisplayEpisodeActivity.class);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this,clickedRow.findViewById(R.id.background), "background");
startActivity(intent, options.toBundle());
Run Code Online (Sandbox Code Playgroud)
我的主题:
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="NewApi">
<style name="BaseTheme" parent="android:Theme.Material.Light.DarkActionBar">
<item name="android:colorPrimary">#D32F2F</item>
<item name="android:textColorPrimary">#616161</item>
<item name="android:colorPrimaryDark">#B71C1C</item>
<item name="android:colorAccent">#757575</item>
<item name="android:colorControlHighlight">#EF9A9A</item>
<item name="android:windowContentTransitions">true</item>
<item name="android:windowSharedElementEnterTransition">
@transition/change_image_transform</item>
<item name="android:windowSharedElementExitTransition">
@transition/change_image_transform</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
change_image_transform.xml:
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<changeTransform/>
<changeBounds/>
</transitionSet>
Run Code Online (Sandbox Code Playgroud)
而且我已经设置了transitionName对android.support.v7.widget.CardView布局的右侧,并在RelativeLayout左边秒.
活动和片段共享转换都很难调试.默认情况下,动画很快,有时眼睛只能看到"有什么不对劲",但要弄清楚什么/为什么可以是非平凡的.
在调试从A到B的共享转换时,我通常发现对Override onMapSharedElements方法非常有用,所以你可以很容易地找出A中哪些共享元素与B中的元素相关联.这样的事情(在B的onCreate()方法中:
setEnterSharedElementCallback(new SharedElementCallback() {
@Override
public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
Log.i(Constants.TAG, "EnterSharedElement.onMapSharedElements:" + sharedElements.size());
//manual override of non-working shared elements goes here
super.onMapSharedElements(names, sharedElements);
}
@Override
public void onRejectSharedElements(List<View> rejectedSharedElements) {
//Some element was rejected? Aha!!
Log.i(Constants.TAG, "EnterSharedElement.onMapSharedElements:" + rejectedSharedElements.size());
super.onRejectSharedElements(rejectedSharedElements);
}
@Override
public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
//AFTER the shared transition
super.onSharedElementEnd(sharedElementNames, sharedElements, sharedElementSnapshots);
}
});
}catch (Exception uie){
Log.e(Constants.TAG,"UIE:"+uie.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
通过这种方式,可以更容易地确定哪些元素未被映射(可能它们尚未创建)并解决共享转换问题(即:毛刺,工件)
| 归档时间: |
|
| 查看次数: |
1908 次 |
| 最近记录: |