像Palabre应用程序一样使用闪屏的Android Material动画

3
这是Palabre视图的启动屏幕:

enter image description here

https://play.google.com/store/apps/details?id=com.levelup.palabre

我们可以看到,在应用程序启动时,有一个带有图像动画的启动屏幕。

这就是我要实现的美丽效果:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/imgLogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/grand_canyon"/>

</RelativeLayout>

结果:

enter image description here

这个SplashActivity有一个全屏视图。

我们如何像Palabre一样将这个图像精确地移动到左侧或右侧?这个屏幕上的图片尺寸是多少?

编辑:

我还发现了这个全屏ImageView:

在你的布局中:

android:scaleType = "centerCrop"

我们需要为这个ImageView添加动画,该怎么做?

谢谢。

3个回答

3
我认为你可以通过混合使用比例和平移动画来实现。
另一个选择是使用AnimationSet(http://developer.android.com/reference/android/animation/AnimatorSet.html)。
编辑:以下是一些ObjectAnimator示例,其中包含多个动画,其中myView是要动画化的视图。请查看此链接以获取有关动画属性(旋转X、旋转Y等)的说明http://developer.android.com/guide/topics/graphics/prop-animation.html#views
 AnimatorSet animSet = new AnimatorSet();
    animSet.playTogether(
         ObjectAnimator.ofFloat(myView, "rotationX", 0, 360),
         ObjectAnimator.ofFloat(myView, "rotationY", 0, 180),
         ObjectAnimator.ofFloat(myView, "rotation", 0, -90),
         ObjectAnimator.ofFloat(myView, "translationX", 0, 90),
         ObjectAnimator.ofFloat(myView, "translationY", 0, 90),
         ObjectAnimator.ofFloat(myView, "scaleX", 1, 1.5f),
         ObjectAnimator.ofFloat(myView, "scaleY", 1, 0.5f),
         ObjectAnimator.ofFloat(myView, "alpha", 1, 0.25f, 1)
    );
 animSet.setDuration(5000).start();

请注意,我指定了以毫秒为单位的动画持续时间。

如果您的目标是低于11的API,请查看http://nineoldandroids.com/以在旧版本的Android上使用AnimatorSet。

希望这可以帮助您。


3

我终于找到它了。它很漂亮 :) 只需添加依赖项:

compile 'com.flaviofaria:kenburnsview:1.0.6' 

并且,

XML布局:

<com.flaviofaria.kenburnsview.KenBurnsView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/img"
        android:scaleType = "centerCrop"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/splash" />

Github: https://github.com/flavioarfaria/KenBurnsView

感谢Flávio Faria开发的这个优秀的库。

但是,它存在一个问题,当图像移动到另一侧时,出现了卡顿或者类似bug的情况,我还没有找到最好的解决方案。


0

这是我认为你应该做的事情

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"  
     android:background="@drawable/ic_splash" >
</RelativeLayout>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接