5

我的平板电脑应用程序针对不同的UI模式有一个活动和几个不同的布局 - 这些布局中的每一个都使用< fragment>标记用不同片段填充UI(setContentView在活动切换模式)。当从XML加载片段时动画片段转换

如何在使用过渡动画淡入新片段时以这种方式加载?现在切换模式会在碎片加载时产生闪烁效果。

谢谢!

+0

您是否试图在布局中加载不同的碎片? –

回答

1

我从来没有使用过碎片,但没有理由为什么碎片会影响我的解决方案。基本上,你实现了一个动画来显示在第一个布局的东西上。最好的例子是一个ListView

首先,你需要添加一些额外的动画文件,添加到RES /阿尼姆

layout_controller.xml:

<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" 
android:delay="50%" 
android:animation="@anim/bounce" /> 

这定义了铺设东西的过程。
然后,bounce.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:interpolator="@android:anim/bounce_interpolator"> 
<translate 
    android:fromXDelta="40%" 
    android:toXDelta="0%" 
    android:fromYDelta="0%" 
    android:toYDelta="0%" 
    android:duration="900"/> 
<alpha 
    android:fromAlpha="0" 
    android:toAlpha="1" 
    android:duration="1000" 
    android:interpolator="@android:anim/linear_interpolator" 
    /> 

这部动画将在反弹的同时该项目也衰落了。

现在,如果你有一个列表视图,它设置这是XML(将适用于textview,imageview等)

<ListView 
android:id="@+id/list" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:persistentDrawingCache="animation|scrolling" 
android:layoutAnimation="@anim/layout_controller" 
/> 

layoutAnimation字段告诉列表视图引用布局控制器如何显示列表视图。当第一次绘制列表视图时,每个项目都应该连续弹出。您可以通过更改bounce.xml轻松定制动画,或通过更改layout_controller中定义的50%延迟更改等待时间。