Twitter 喜欢 Android ImageView 的动画?

Twitter like Animation for an Android ImageView?

iOS 上的 Twitter 开始时有这个漂亮的小鸟动画。

(Source)

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

它叫做启动画面,这里有一个教程如何实现它 - link

不同的是需要在行后添加

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>

简单如:

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>

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

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

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

THis link 可能对您有用 下载 代码并按照 link 建议

您可以在代码中创建:

// 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" />

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

--> 运行 动画和监听动画事件(listener可以留空)

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

}

@Override
public void onUpdate(float completionFraction){

}

@Override
public void onEnd(){

}

});`

输出将是

-希望你能找到答案。