1.欢迎页布局
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/iv_Welcome" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="fitXY"/> <TextView android:id="@+id/tv_Welcome" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="跳过" android:textColor="@android:color/black" android:layout_marginLeft="300dp" android:layout_marginTop="20dp"/> </RelativeLayout>
2.WelcomeActivity
package com.example.dllo.telbook; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.AsyncTask; import android.os.Bundle; import android.os.CountDownTimer; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; /** * Created by dllo on 16/6/14. */ public class WelcomeActivity extends Activity { private ImageView imageView; private TextView textView; private CountDownTimer countDownTimer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_welcome); imageView = (ImageView) findViewById(R.id.iv_Welcome); new BitmapAsyncTask().execute("http://p4.image.hiapk.com/uploads/allimg/150115/7730-150115152A5.jpg"); textView = (TextView) findViewById(R.id.tv_Welcome); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { countDownTimer.cancel(); startActivity(new Intent(WelcomeActivity.this, MainActivity.class)); finish(); } }); countDownTimer = new CountDownTimer(8000, 1000) { @Override public void onTick(long millisUntilFinished) { textView.setText("跳过:" + millisUntilFinished / 1000 + "S"); } @Override public void onFinish() { startActivity(new Intent(WelcomeActivity.this, MainActivity.class)); finish(); } }.start(); } class BitmapAsyncTask extends AsyncTask<String, Void, Bitmap> { @Override protected Bitmap doInBackground(String... params) { String imageUrl = params[0]; Bitmap bitmap; HttpURLConnection connection = null; InputStream inputStream = null; try { URL url = new URL(imageUrl); connection = (HttpURLConnection) url.openConnection(); inputStream = connection.getInputStream(); bitmap = BitmapFactory.decodeStream(inputStream); return bitmap; } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { inputStream.close(); connection.disconnect(); } catch (IOException e) { e.printStackTrace(); } } return null; } @Override protected void onPostExecute(Bitmap bitmap) { super.onPostExecute(bitmap); imageView.setImageBitmap(bitmap); } } }