8

我希望在活动转换上的共享元素上实现放大动画,就像在此link中一样。如何在活动转换上的共享元素上实现放大动画

但找不到任何有关此特定效果的良好参考以及如何实现它。这是自定义过渡还是默认?也许任何人都可以帮助或发布更详细的教程,而不是官方文档。

+1

格纹是真棒。这可能会有帮助。 https://github.com/nickbutcher/plaid – nshmura

+0

试试这个教程:http://www.androidhive.info/2013/06/android-working-with-xml-animations/ –

+1

试试这个https://开头github上。 COM/lgvalle /材料的动画 – KrishnaJ

回答

6

让我给你一个简短的教程这里:)

Shared element transition

你真正想要的是一个共享的元素两项活动之间的过渡。你实际上不会分享任何观点,两个活动都会有独立的观点树。但是我们会将有关共享元素的信息(如其视图和大小)传递给新活动。

启动时,新活动将使其所有视图都透明,并查找共享视图。它改变其属性以匹配从启动活动传入的那些 ,并使该单个视图可见。然后运行动画将共享视图从此状态转换为布局中的自然位置。随着转换的进行,窗口背景和其他非共享元素缓慢地褪去,直到它们完全不透明为止。所有这些都是自动完成的。

现在标记的视图,作为共享设置此属性:在两个活动布局

<ImageView 
... 
android:transitionName="@string/transition_photo" /> 

现在同时开始从老年活动新的活动定义一个过渡动画:

Bundle bundle = ActivityOptions.makeSceneTransitionAnimation(
            this, 
            sharedView, 
            sharedView.getTransitionName()) 
           .toBundle(); 
startActivity(intent,bundle); 

您还可以指定为过渡多个视图。你甚至可以转换不同的应用程序之间共享的看法。

默认使用的动画举动

<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"> 
<changeBounds/> 
<changeTransform/> 
<changeClipBounds/> 
<changeImageTransform/> 
</transitionSet> 

但你也可以设置自定义动画在styles.xml:

<style name="AppTheme.Details"> 
    <item name="android:windowSharedElementEnterTransition">@transition/shared_photo</item> 
</style> 

这里是共享元素过渡的工作示例如上所示: https://github.com/anshchauhan/SharedElementTransition

0

创建XML和使用动画下面的代码:

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    overridePendingTransition(animation_in, animation_out); 
} 

RES /动画/ in.xml

<?xml version="1.0" encoding="utf-8"?> 
    <set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/linear_interpolator"> 

    <scale 
     android:duration="700" 
     android:fillBefore="false" 
     android:fromXScale="0.0" 
     android:fromYScale="0.0" 
     android:toXScale="1.0" 
     android:toYScale="1.0" /> 
</set> 

RES /动画/ out.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/linear_interpolator"> 

    <scale 
     android:duration="700" 
     android:fillBefore="false" 
     android:fromXScale="1.0" 
     android:fromYScale="1.0" 
     android:toXScale="0.0" 
     android:toYScale="0.0" /> 
</set> 
+0

的问题是,它应该是什么样的动画具有相同的结果 – Datenshi

+0

@Datenshi,更新我的答案。希望这将帮助你:) – Neo

0

https://www.youtube.com/watch?v=CPxkoe2MraA

此视频解释如何实现相同的结果。主要想法是

1)覆盖自定义默认动画。这里0表示默认情况下不播放动画。

overridePendingTransition(0, 0); 

2)翻译和第二活动图像扩展到你的GridView图像,使其完全盖过它,然后将动画应用于活动的imageview的移动原来的位置和规模。

此外看一看共享元素活动转变 - https://guides.codepath.com/android/Shared-Element-Activity-Transition

0

1:发现视图规格:

int[] location = new int[2]; 
view.getLocationOnScreen(location); 

int viewHeight = view.getHeight(); 
int viewWidth = view.getWidth(); 

2:建立一个透明的活性,并通过顶部值以新的活动

3:将您的视图添加到新的活动,并做这样的事情:

LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) yourView.getLayoutParams(); 
layoutParams.topMargin = location[1]; 
layoutParams.leftMargin = location[0]; 
layoutParams.height = viewHeight; 
layoutParams.width = viewWidth; 
yourView.setLayoutParams(layoutParams); 

4:使用像@ neo的答案的动画缩放yourView填补屏幕

相关问题