Java Android ImageView的类似Twitter的动画?

Java Android ImageView的类似Twitter的动画?,java,android,animation,imageview,android-animation,Java,Android,Animation,Imageview,Android Animation,iOS上的Twitter在一开始就有一个漂亮的小鸟动画 () 如何使用Android ImageView制作这样的动画?它被称为闪屏,下面是如何实现它的教程- 不同之处在于,您需要在第行之后添加 setContentView(R.layout.activity_splash); 以下代码: ImageView image = (ImageView) findViewById(R.id.imgLogo); Animation animation = AnimationUtils.loadAnim

iOS上的Twitter在一开始就有一个漂亮的小鸟动画

()


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

它被称为闪屏,下面是如何实现它的教程-

不同之处在于,您需要在第行之后添加

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>


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

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

同意上述答案,但还有另一个解决方案:-

可能对您有用,只需下载代码并按照链接建议

您可以在代码中创建:

// 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);
<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" />
或在XML中:

// 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);
<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" />
}))`

输出将为


-希望您能找到答案。

检查缩放+Alpha动画我什么时候需要在
onStart()中调用此选项。
?你能添加一个代码示例吗?请参考此链接,如果你给出答案,我可以接受。不,这不是正确的答案。它应该从中心开始缩放。是否可以更改动画?第一个反弹动画没有出现在我的代码中。对此,该怎么办?@confile同时检查此库