<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="match_parent" android:background="@drawable/bg_ling" > <ImageView android:id="@+id/image" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/welcome" /> <TextView android:id="@+id/compete" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/hello_world" /> <ProgressBar android:id="@+id/prograssBar" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@android:attr/progressBarStyle" android:visibility="gone" android:layout_above="@id/compete" android:layout_centerHorizontal="true"/> </RelativeLayout>
package cn.bzu.alphaanimation; import android.os.Bundle; import android.os.Handler; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.animation.AlphaAnimation; import android.widget.ImageView; import android.widget.ProgressBar; public class AlphaAnimationActivity extends Activity { private ProgressBar progressBar; private ImageView image; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_alpha_animation); progressBar=(ProgressBar) this.findViewById(R.id.prograssBar); image=(ImageView) this.findViewById(R.id.image); progressBar.setVisibility(View.VISIBLE); //创建一个淡入效果的Animation对象 AlphaAnimation animation=new AlphaAnimation(0.0f, 0.1f); animation.setDuration(1000); animation.setStartOffset(500); image.setAnimation(animation); new Handler().postDelayed(new Runnable() { // 新建一个handler实现演示跳转 @Override public void run() { Intent intent= new Intent(); intent.setClass(AlphaAnimationActivity.this, MainActivity.class); startActivity(intent); } }, 1500); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_alpha_animation, menu); return true; } }