就像简单的这样:
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>
要进一步修改动画,您可以:
这叫做启动屏幕,这里有一个教程告诉你如何实现它 - 链接
不同之处在于你需要在代码的某一行之后添加:
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>
同意上面的答案,但还有另一种解决方案:
这个链接可能对你有用,只需下载代码,按照链接提示进行操作。
你可以在代码中创建:
// 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(){
}
});`
输出结果将是
- 希望你能找到答案。