类似Twitter的Android ImageView动画?

3

iOS版Twitter在启动时有一种很好看的小鸟动画。

enter image description here (源码)

我如何使用Android ImageView制作这样的动画?


请查看此链接:https://github.com/mohit008/Android-Animation/tree/master/src/com/example/animation - Iamat8
1
缩放 + 透明度动画 - Blackbelt
我什么时候需要在“onStart()”中调用它?你能添加一个代码示例吗? - Michael
1
请参考此链接:http://www.androidhive.info/2013/06/android-working-with-xml-animations/。 - Rajan Kali
请查看此链接:https://github.com/ozodrukh/CircularReveal - IntelliJ Amiya
@confile 检查我的答案和相关链接,尽管答案已经被接受,但也有一个适用于安卓的库。 - Hardy
3个回答

4

就像简单的这样:

findViewById(R.id.image_view).animate()
    .setStartDelay(500)
    .setDuration(1000)
    .scaleX(20)
    .scaleY(20)
    .alpha(0);

确保图像视图在您的布局中居中显示:
<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <ImageView
    android:id="@+id/image_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:src="@mipmap/ic_launcher"/>
</FrameLayout>

要进一步修改动画,您可以:

  • 延迟动画
  • 使用减速(或其他)插值器
  • 修改比例因子

是否可以更改动画效果? - Michael
我的代码中第一个弹跳动画没有出现,我该怎么办? - Mahalakshmi Saravanan

2

这叫做启动屏幕,这里有一个教程告诉你如何实现它 - 链接

不同之处在于你需要在代码的某一行之后添加:

setContentView(R.layout.activity_splash);

以下代码:

ImageView image = (ImageView) findViewById(R.id.imgLogo);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.my_animation); 
image.startAnimation(animation);

并在res/anim中添加一个新文件my_animation.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:fromXScale="1.0" android:fromYScale="1.0"
          android:toXScale="5.0" android:toYScale="5.0" 
          android:duration="3000" android:fillBefore="false"
          android:pivotX="50%" android:pivotY="50%" />

   <alpha android:fromAlpha="1.0" android:toAlpha="0.0" 
          android:duration="3000"/>

</set>

不,这不是正确的。它应该从中心缩放。 - Michael

0

同意上面的答案,但还有另一种解决方案:

这个链接可能对你有用,只需下载代码,按照链接提示进行操作。

你可以在代码中创建:

// create and customize the view
SplashView splashView = new SplashView(context);
// the animation will last 0.5 seconds
splashView.setDuration(500);
// transparent hole will look white before the animation
splashView.setHoleFillColor(Color.WHITE);
// this is the Twitter blue color
splashView.setIconColor(Color.rgb(23, 169, 229));
// a Twitter icon with transparent hole in it
splashView.setIconResource(R.drawable.ic_twitter);
// remove the SplashView from MainView once animation is completed
splashView.setRemoveFromParentOnEnd(true);

或者在XML中:

<com.yildizkabaran.twittersplash.view.SplashView 
    xmlns:app="http://schemas.android.com/apk/res/com.yildizkabaran.twittersplash"
    android:id="@+id/splash_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:icon="@drawable/ic_twitter"
    app:iconColor="@color/twitter_blue"
    app:duration="500"
    app:holeFillColor="@color/white"
    app:removeFromParentOnEnd="true" />

然后要运行动画,只需调用:

--> 运行动画并监听动画事件(监听器可以保留为空)

splashView.splashAndDisappear(new ISplashListener(){
    @Override
    public void onStart(){

}

@Override
public void onUpdate(float completionFraction){

}

@Override
public void onEnd(){

}

});`

输出结果将是

enter image description here

- 希望你能找到答案。

@confile 也请检查一下这个库。 - Hardy

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