Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 關於android開發 >> android軟件引導界面

android軟件引導界面

編輯:關於android開發

android軟件引導界面


軟件的引導界面


·大多數軟件在安裝成功後的第一次運行,或版本更新後的第一次運行時
會使用3-5張圖片對軟件的使用,版本更新作簡單的介紹或演示,這樣的界面稱之為“引導界面”


·在切換顯示到最後一張圖片時,點擊按鈕即可進入軟件的主界面,且以後再次運行該應用程序時都不再顯示引導界面


案例相關知識點包括:
·手勢判斷
·ImageSwitcher控件;
·動畫;

·SharedPreferences

 

Guide的xml布局界面:

 



    
    


 

 

GuideActivity.java

 

package com.example;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Point;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.ViewSwitcher.ViewFactory;

public class GuideActivity extends Activity {
	private ImageSwitcher mImageSwitcher;
	private int[] mImgResIds;
	private int mCurrentImageIndx;
	private Point mDownPoint = new Point();
	
	private Animation mRight2LeftIn,mRight2leftOut;
	
	private String filename = "config";
	private String firstRunning = "true";



	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_guide);
		SharedPreferences sp = getSharedPreferences(filename, MODE_PRIVATE);
		String config = sp.getString(firstRunning, null);
		if(config != null){
			Intent intent = new Intent(this, MainActivity.class);
			startActivity(intent);
			finish();
		}
		mImageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher);
		mImgResIds = new int[]{
				R.drawable.image01,
				R.drawable.image02,
				R.drawable.image03,
				R.drawable.image04

		};

		/*
		 * 給使用setFactoru給mImageSwitcher添加兩個子級控件
		 */

		mImageSwitcher.setFactory(new ViewFactory() {

			@Override
			public View makeView() {
				// TODO Auto-generated method stub
				ImageView v = new ImageView(getApplicationContext());


				//這裡是內部類所以不能用this 要用getApplicationContext()
				v.setScaleType(ScaleType.FIT_XY);
				v.setImageResource(mImgResIds[mCurrentImageIndx]);

				return v;
			}
		});
		mRight2LeftIn = AnimationUtils.loadAnimation(this, R.anim.right2left_in);
		mRight2leftOut = AnimationUtils.loadAnimation(this, R.anim.right2left_out);
	}
	/**
	 * 判斷手勢
	 */
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			mDownPoint.x = (int) event.getX();
			break;
		case MotionEvent.ACTION_UP:
			if(event.getX() - mDownPoint.x >10){
				//left ->right :previous

			}
			if(mDownPoint.x - event.getX() >10){
				// right->left :next
				if(mCurrentImageIndx < mImgResIds.length - 1){
					mCurrentImageIndx++;
					((ImageView)mImageSwitcher.getNextView()).setImageResource(mImgResIds[mCurrentImageIndx]);
					mImageSwitcher.setInAnimation(mRight2LeftIn);
					mImageSwitcher.setOutAnimation(mRight2leftOut);
					mImageSwitcher.showNext();
					/*
					 * 判斷如果到最後一張圖片就顯示按鈕
					 * */
					if(mCurrentImageIndx == mImgResIds.length - 1){
						findViewById(R.id.btn_go_to_main).setVisibility(View.VISIBLE);
					}
				}
			}
			break;

		default:
			break;
		}
		return super.onTouchEvent(event);
	}
	public void startMain(View v){
		SharedPreferences sp = getSharedPreferences(filename, MODE_PRIVATE);
		Editor editor = sp.edit();
		editor.putString(firstRunning, "false");
		editor.commit();
		Intent intent = new Intent(this,MainActivity.class);
		startActivity(intent);
		finish();//引導界面的Activity就會退出,回退棧中也會清除該Activity,點擊回退按鈕也不會回退到引導界面
	}


}

切換動畫效果實現xml

 

right2left_in

 

 


    


right2left_out.xml

 

 

 

 
    



 

 

 

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved