布局:
main.xml:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center_horizontal" > <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/logo" /> <TextView android:id="@+id/tv" android:text="Welcom to mojia space" android:layout_below="@drawable/logo" android:layout_width="wrap_content" android:layout_height="wrap_content" /></RelativeLayout>
other.xml:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center_horizontal" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="Button" /></RelativeLayout>
主Activity:
package wangxin.Activity;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.widget.ImageView;import android.widget.TextView;public class WelcomePicActivity extends Activity {/** Called when the activity is first created. */private TextView tv = null;private ImageView image = null;private Handler handler = null;private int alpha = 255;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);tv = (TextView) findViewById(R.id.tv);image = (ImageView) findViewById(R.id.image);image.setAlpha(alpha);Thread thread = new Thread(new UpdateImageThread());thread.start();handler = new Handler() {@Overridepublic void handleMessage(Message msg) {// TODO Auto-generated method stubSystem.out.println(msg);super.handleMessage(msg);image.setAlpha(alpha);image.invalidate();}};}class UpdateImageThread implements Runnable{private int b =0 ;@Overridepublic void run() {// TODO Auto-generated method stubb = initApp();try {while (b < 2) {if (b == 0) {//延時2秒後,每50毫秒更新一次imageThread.sleep(2000);b = 1;} else {Thread.sleep(50);}updateApp(b);}} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}protected void updateApp(int b) {// TODO Auto-generated method stubalpha = alpha - 5;if (alpha <= 0) {b = 2;Intent intent = new Intent(this, Frm_Addbills.class);startActivity(intent);finish();}handler.sendMessage(handler.obtainMessage());}public int initApp() {int b = 0;return b;}}
otherActivity:
package wangxin.Activity;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class Frm_Addbills extends Activity {private Button btn = null;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.other);btn = (Button) findViewById(R.id.button1);btn.setOnClickListener(new BtnListener());}class BtnListener implements OnClickListener {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubFrm_Addbills.this.finish();}}}