写了一个Android动画的启动界面
如何创建项目我就不多说了。这次为大家演示一下Android动画启动。也许你会找到更为优化的方法。这种方法只是仅供参考。我也是Android菜鸟,下面不多说为大家分享下我的实现

1 package com.DIY.picView; 2 3 import android.app.Activity; 4 import android.content.Intent; 5 import android.os.Bundle; 6 import android.view.animation.Animation; 7 import android.view.animation.Animation.AnimationListener; 8 import android.view.animation.AnimationUtils; 9 import android.widget.ImageView; 10 11 public class loginActivity extends Activity implements AnimationListener{ 12 13 private ImageView _ivWelcome; 14 15 @Override 16 protected void onCreate(Bundle savedInstanceState) { 17 // TODO Auto-generated method stub 18 super.onCreate(savedInstanceState); 19 setContentView(R.layout.login_view); 20 _ivWelcome = (ImageView)findViewById(R.id.iv_Welcome); 21 Animation animation = AnimationUtils.loadAnimation(this, R.anim.anim_fit); 22 animation.setAnimationListener(this); 23 _ivWelcome.setAnimation(animation); 24 } 25 26 @Override 27 public void onAnimationEnd(Animation animation) { 28 startActivity(new Intent(this,MainActivity.class)); 29 finish(); 30 31 } 32 33 @Override 34 public void onAnimationRepeat(Animation animation) { 35 // TODO Auto-generated method stub 36 37 } 38 39 @Override 40 public void onAnimationStart(Animation animation) { 41 // TODO Auto-generated method stub 42 43 } 44 45 46 }
在MainActivity中我没有进行操作,原因是这次我们主要实现Android的动画启动。

1 package com.DIY.picView; 2 3 import android.os.Bundle; 4 import android.app.Activity; 5 import android.view.Menu; 6 7 public class MainActivity extends Activity { 8 9 @Override 10 protected void onCreate(Bundle savedInstanceState) { 11 super.onCreate(savedInstanceState); 12 setContentView(R.layout.activity_main); 13 } 14 15 @Override 16 public boolean onCreateOptionsMenu(Menu menu) { 17 // Inflate the menu; this adds items to the action bar if it is present. 18 getMenuInflater().inflate(R.menu.main, menu); 19 return true; 20 } 21 22 }
这是login_activity的XML布局文件,当然了主要是LinearLayout布局。

1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" > 6 7 <ImageView 8 android:id="@+id/iv_Welcome" 9 android:layout_width="fill_parent" 10 android:layout_height="fill_parent" 11 android:background="@drawable/bg" /> 12 13 </LinearLayout>
下面的是activity_main的XML布局文件,这里没有操作,原因上面已说

1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:paddingBottom="@dimen/activity_vertical_margin" 6 android:paddingLeft="@dimen/activity_horizontal_margin" 7 android:paddingRight="@dimen/activity_horizontal_margin" 8 android:paddingTop="@dimen/activity_vertical_margin" 9 tools:context=".MainActivity" > 10 11 <TextView 12 android:layout_width="wrap_content" 13 android:layout_height="wrap_content" 14 android:text="@string/hello_world" /> 15 16 </RelativeLayout>
下面是一个文件也是最关键的,是anim的XML文件,主要实现动画的效果就全靠它了,里面的alpha主要实现了透明度的效果

1 <?xml version="1.0" encoding="utf-8"?> 2 <alpha xmlns:android="http://schemas.android.com/apk/res/android" 3 android:duration="3000" 4 android:fromAlpha="0.0" 5 android:toAlpha="1.0" 6 android:interpolator="@android:anim/accelerate_interpolator" 7 > 8 </alpha>
最后是AndroidManifest配置文件

1 <?xml version="1.0" encoding="utf-8"?> 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.DIY.picView" 4 android:versionCode="1" 5 android:versionName="1.0" > 6 7 <uses-sdk 8 android:minSdkVersion="8" 9 android:targetSdkVersion="18" /> 10 11 <application 12 android:allowBackup="true" 13 android:icon="@drawable/logo" 14 android:label="@string/app_name" 15 android:theme="@style/AppTheme" > 16 <activity 17 android:name="com.DIY.picView.MainActivity" 18 android:label="@string/app_name" 19 > 20 </activity> 21 <activity 22 android:name="loginActivity" 23 android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 24 android:screenOrientation="portrait" 25 > 26 <intent-filter> 27 <action android:name="android.intent.action.MAIN" /> 28 29 <category android:name="android.intent.category.LAUNCHER" /> 30 </intent-filter> 31 </activity> 32 </application> 33 </manifest>
运行后的效果图:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步