源碼地址: http://www.eoeandroid.com/thread-584730-1-1.html
應用在第一次啓動時,應先進入引導頁面。怎樣判斷應用是否是第一次使用呢?這裏我使用SharedPreferences 和 酷狗的 引導頁面爲例子,大概看了一下酷狗apk包裏面的圖片,發現酷狗的文字動畫 裏的文字 原來是 圖片文字,不過這裏我 就不用它 的圖片文字,而是用textview來實現。
首先定義一個 Constants 類來 儲存 SharedPreferences 配置文件的 內容。-
package com.happy.common;
-
-
public class Constants {
-
/**
-
* --------------------------應用配置--------------------------
-
**/
-
-
/**
-
* 配置文件的名稱
-
*/
-
public static String PREFERENCE_NAME = "happy.sharepreference.name";
-
/**
-
* 是否是第一次運行的key
-
*/
-
public static String ISFIRST_KEY = "ISFIRST_KEY";
-
/**
-
* 是否是第一次運行
-
*/
-
public static boolean ISFIRST = true;
-
}
-
package com.happy.util;
-
-
import android.content.Context;
-
import android.content.SharedPreferences;
-
import android.content.SharedPreferences.Editor;
-
-
import com.happy.common.Constants;
-
-
/**
-
* SharedPreferences配置文件處理
-
*
-
* @author zhangliangming
-
*
-
*/
-
public class DataUtil {
-
private static SharedPreferences preferences;
-
-
/**
-
* 初始化,將所有配置文件裏的數據賦值給Constants
-
*
-
* @param context
-
*/
-
public static void init(Context context) {
-
if (preferences == null) {
-
preferences = context.getSharedPreferences(
-
Constants.PREFERENCE_NAME, 0);
-
}
-
}
-
-
/**
-
* 保存數據到SharedPreferences配置文件
-
*
-
* @param context
-
* @param key
-
* 關鍵字
-
* @param data
-
* 要保存的數據
-
*/
-
public static void saveValue(Context context, String key, Object data) {
-
if (preferences == null) {
-
preferences = context.getSharedPreferences(
-
Constants.PREFERENCE_NAME, 0);
-
}
-
Editor editor = preferences.edit();
-
if (data instanceof Boolean) {
-
editor.putBoolean(key, (Boolean) data);
-
} else if (data instanceof Integer) {
-
editor.putInt(key, (Integer) data);
-
} else if (data instanceof String) {
-
editor.putString(key, (String) data);
-
} else if (data instanceof Float) {
-
editor.putFloat(key, (Float) data);
-
} else if (data instanceof Long) {
-
editor.putFloat(key, (Long) data);
-
}
-
-
// 提交修改
-
editor.commit();
-
}
-
-
/**
-
* 從SharedPreferences配置文件中獲取數據
-
*
-
* @param context
-
* @param key
-
* 關鍵字
-
* @param defData
-
* 默認獲取的數據
-
* @return
-
*/
-
public static Object getValue(Context context, String key, Object defData) {
-
if (preferences == null) {
-
preferences = context.getSharedPreferences(
-
Constants.PREFERENCE_NAME, 0);
-
}
-
-
if (defData instanceof Boolean) {
-
return preferences.getBoolean(key, (Boolean) defData);
-
} else if (defData instanceof Integer) {
-
return preferences.getInt(key, (Integer) defData);
-
} else if (defData instanceof String) {
-
return preferences.getString(key, (String) defData);
-
} else if (defData instanceof Float) {
-
return preferences.getFloat(key, (Float) defData);
-
} else if (defData instanceof Long) {
-
return preferences.getLong(key, (Long) defData);
-
}
-
-
return null;
-
-
}
-
}
-
package com.happy.ui;
-
-
import android.app.Activity;
-
import android.content.Intent;
-
import android.os.AsyncTask;
-
import android.os.Bundle;
-
import android.os.Handler;
-
import android.os.Message;
-
import android.view.Menu;
-
import android.widget.ImageView;
-
-
import com.happy.common.Constants;
-
import com.happy.util.DataUtil;
-
-
public class SplashActivity extends Activity {
-
/**
-
* 跳轉到主頁面
-
*/
-
private final int GOHOME = 0;
-
/**
-
* 跳轉到引導頁面
-
*/
-
private final int GOGUIDE = 1;
-
/**
-
* 頁面停留時間 3s
-
*/
-
private final int SLEEPTIME = 3000;
-
/**
-
* splash ImageView
-
*/
-
private ImageView splashImageView = null;
-
-
private Handler mHandler = new Handler() {
-
-
@Override
-
public void handleMessage(Message msg) {
-
switch (msg.what) {
-
case GOHOME:
-
goHome();
-
break;
-
case GOGUIDE:
-
goGuide();
-
break;
-
-
default:
-
break;
-
}
-
}
-
-
};
-
-
@Override
-
protected void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
setContentView(R.layout.activity_splash);
-
init();
-
loadData();
-
}
-
-
@Override
-
public boolean onCreateOptionsMenu(Menu menu) {
-
getMenuInflater().inflate(R.menu.splash, menu);
-
return true;
-
}
-
-
private void init() {
-
splashImageView = (ImageView) findViewById(R.id.splash);
-
splashImageView.setBackgroundResource(R.drawable.splash);
-
}
-
-
private void loadData() {
-
new AsyncTask<String, Integer, Integer>() {
-
-
@Override
-
protected Integer doInBackground(String... params) {
-
-
boolean isFrist = (Boolean) DataUtil.getValue(
-
SplashActivity.this, Constants.ISFIRST_KEY,
-
Constants.ISFIRST);
-
// 第一次執行
-
if (isFrist) {
-
return GOGUIDE;
-
}
-
// 配置數據初始化
-
DataUtil.init(SplashActivity.this);
-
return GOHOME;
-
}
-
-
@Override
-
protected void onPostExecute(Integer result) {
-
-
// 根據返回的result 跳轉到不同的頁面
-
mHandler.sendEmptyMessageDelayed(result, SLEEPTIME);
-
}
-
-
}.execute("");
-
-
}
-
-
/**
-
* 跳轉到引導頁面
-
*/
-
protected void goGuide() {
-
Intent intent = new Intent(this, GuideActivity.class);
-
startActivity(intent);
-
// 添加界面切換效果,注意只有Android的2.0(SdkVersion版本號爲5)以後的版本才支持
-
int version = Integer.valueOf(android.os.Build.VERSION.SDK);
-
if (version >= 5) {
-
overridePendingTransition(R.anim.anim_in, R.anim.anim_out);
-
}
-
finish();
-
}
-
-
/**
-
* 跳轉到主界面
-
*/
-
protected void goHome() {
-
Intent intent = new Intent(this, MainActivity.class);
-
startActivity(intent);
-
// 添加界面切換效果,注意只有Android的2.0(SdkVersion版本號爲5)以後的版本才支持
-
int version = Integer.valueOf(android.os.Build.VERSION.SDK);
-
if (version >= 5) {
-
overridePendingTransition(R.anim.anim_in, R.anim.anim_out);
-
}
-
finish();
-
}
-
}
-
package com.happy.ui;
-
-
import java.util.ArrayList;
-
-
import android.graphics.Color;
-
import android.os.Bundle;
-
import android.support.v4.app.Fragment;
-
import android.support.v4.app.FragmentActivity;
-
import android.support.v4.app.FragmentManager;
-
import android.support.v4.app.FragmentPagerAdapter;
-
import android.support.v4.view.ViewPager;
-
import android.support.v4.view.ViewPager.OnPageChangeListener;
-
import android.view.KeyEvent;
-
import android.view.Menu;
-
import android.widget.ImageView;
-
import android.widget.Toast;
-
-
import com.happy.fragment.GuideFragment;
-
import com.happy.manage.ActivityManage;
-
-
public class GuideActivity extends FragmentActivity {
-
private ViewPager viewPager;
-
private TabFragmentPagerAdapter tabFragmentPagerAdapter;
-
/**
-
* 頁面列表
-
*/
-
private ArrayList<Fragment> fragmentList;
-
-
private GuideFragment firstGuideFragment;
-
private GuideFragment secondGuideFragment;
-
private GuideFragment thirdGuideFragment;
-
private GuideFragment fourthGuideFragment;
-
-
/** 將小圓點的圖片用數組表示 */
-
private ImageView[] imageViews;
-
/**
-
* 當前索引
-
*/
-
private int TAB_INDEX = 0;
-
-
private long mExitTime;
-
-
@Override
-
protected void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
setContentView(R.layout.activity_guide);
-
init();
-
// 將activity添加到ActivityManage
-
ActivityManage.getInstance().addActivity(this);
-
}
-
-
@Override
-
public boolean onCreateOptionsMenu(Menu menu) {
-
getMenuInflater().inflate(R.menu.guide, menu);
-
return true;
-
}
-
-
/**
-
* 初始化
-
*/
-
private void init() {
-
viewPager = (ViewPager) findViewById(R.id.viewpager);
-
fragmentList = new ArrayList<Fragment>();
-
-
//
-
firstGuideFragment = new GuideFragment();
-
firstGuideFragment.setParentRelativeLayoutColor(Color
-
.rgb(163, 161, 212));
-
firstGuideFragment.setMainTitleText("猜你喜歡");
-
firstGuideFragment.setSecondTitleText("總能猜到,你愛聽的。");
-
firstGuideFragment.setCentPICImage(R.drawable.guide_first_person);
-
firstGuideFragment.setInitAni(true);
-
//
-
secondGuideFragment = new GuideFragment();
-
secondGuideFragment.setParentRelativeLayoutColor(Color.rgb(254, 153,
-
153));
-
secondGuideFragment.setMainTitleText("蝰蛇音效");
-
secondGuideFragment.setSecondTitleText("三大神器,聽覺重生。");
-
secondGuideFragment.setCentPICImage(R.drawable.guide_second_person);
-
//
-
thirdGuideFragment = new GuideFragment();
-
thirdGuideFragment
-
.setParentRelativeLayoutColor(Color.rgb(225, 184, 94));
-
thirdGuideFragment.setMainTitleText("聽歌識曲");
-
thirdGuideFragment.setSecondTitleText("全新改版,更快更準。");
-
thirdGuideFragment
-
.setCentPICImage(R.drawable.guide_third_bottom_person);
-
//
-
fourthGuideFragment = new GuideFragment();
-
fourthGuideFragment.setParentRelativeLayoutColor(Color
-
.rgb(77, 199, 255));
-
fourthGuideFragment.setMainTitleText("K歌送禮");
-
fourthGuideFragment.setSecondTitleText("免費領K幣,送禮推榜首。");
-
fourthGuideFragment
-
.setCentPICImage(R.drawable.guide_four_bottom_person);
-
fourthGuideFragment.setGoToImageViewVisibility(true);
-
//
-
fragmentList.add(firstGuideFragment);
-
fragmentList.add(secondGuideFragment);
-
fragmentList.add(thirdGuideFragment);
-
fragmentList.add(fourthGuideFragment);
-
-
// 創建imageviews數組,大小是要顯示的圖片的數量
-
imageViews = new ImageView[fragmentList.size()];
-
-
int i = 0;
-
imageViews[i++] = (ImageView) findViewById(R.id.point_1);
-
imageViews[i++] = (ImageView) findViewById(R.id.point_2);
-
imageViews[i++] = (ImageView) findViewById(R.id.point_3);
-
imageViews[i++] = (ImageView) findViewById(R.id.point_4);
-
-
for (int j = 0; j < imageViews.length; j++) {
-
if (j != 0) {
-
imageViews[j]
-
.setBackgroundResource(R.drawable.music_zone_indicator_common);
-
} else {
-
imageViews[j]
-
.setBackgroundResource(R.drawable.music_zone_indicator_current);
-
}
-
}
-
-
tabFragmentPagerAdapter = new TabFragmentPagerAdapter(
-
getSupportFragmentManager());
-
viewPager.setAdapter(tabFragmentPagerAdapter);
-
viewPager.setOnPageChangeListener(new TabOnPageChangeListener());
-
viewPager.setCurrentItem(0);
-
}
-
-
/**
-
*
-
* @author Administrator Fragment滑動事件
-
*/
-
public class TabFragmentPagerAdapter extends FragmentPagerAdapter {
-
-
public TabFragmentPagerAdapter(FragmentManager fm) {
-
super(fm);
-
}
-
-
@Override
-
public Fragment getItem(int arg0) {
-
return fragmentList.get(arg0);
-
}
-
-
@Override
-
public int getCount() {
-
return fragmentList.size();
-
}
-
}
-
-
/**
-
*
-
* viewpager的監聽事件
-
*
-
*/
-
private class TabOnPageChangeListener implements OnPageChangeListener {
-
-
public void onPageScrollStateChanged(int arg0) {
-
-
}
-
-
public void onPageScrolled(int arg0, float arg1, int arg2) {
-
-
}
-
-
public void onPageSelected(int position) {
-
-
// 設置導航索引
-
for (int i = 0; i < imageViews.length; i++) {
-
// 不是當前選中的page,其小圓點設置爲未選中的狀態
-
if (position != i) {
-
imageViews[i]
-
.setBackgroundResource(R.drawable.music_zone_indicator_common);
-
} else {
-
imageViews[position]
-
.setBackgroundResource(R.drawable.music_zone_indicator_current);
-
}
-
}
-
-
boolean isRightToLeft = false;
-
if (TAB_INDEX < position) {
-
isRightToLeft = true;
-
}
-
TAB_INDEX = position;
-
switch (position) {
-
case 0:
-
firstGuideFragment.startTitleAnimation(isRightToLeft);
-
-
secondGuideFragment.stopAnimation();
-
thirdGuideFragment.stopAnimation();
-
fourthGuideFragment.stopAnimation();
-
break;
-
case 1:
-
secondGuideFragment.startTitleAnimation(isRightToLeft);
-
-
firstGuideFragment.stopAnimation();
-
thirdGuideFragment.stopAnimation();
-
fourthGuideFragment.stopAnimation();
-
break;
-
case 2:
-
thirdGuideFragment.startTitleAnimation(isRightToLeft);
-
-
firstGuideFragment.stopAnimation();
-
secondGuideFragment.stopAnimation();
-
fourthGuideFragment.stopAnimation();
-
break;
-
case 3:
-
fourthGuideFragment.startTitleAnimation(isRightToLeft);
-
-
firstGuideFragment.stopAnimation();
-
secondGuideFragment.stopAnimation();
-
thirdGuideFragment.stopAnimation();
-
break;
-
default:
-
break;
-
}
-
}
-
}
-
-
@Override
-
public boolean onKeyDown(int keyCode, KeyEvent event) {
-
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
-
if ((System.currentTimeMillis() - mExitTime) > 2000) {
-
Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
-
mExitTime = System.currentTimeMillis();
-
} else {
-
ActivityManage.getInstance().exit();
-
}
-
return false;
-
}
-
return super.onKeyDown(keyCode, event);
-
}
-
}
-
<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="fill_parent"
-
tools:context=".GuideActivity" >
-
-
<android.support.v4.view.ViewPager
-
android:id="@+id/viewpager"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:overScrollMode="never" >
-
</android.support.v4.view.ViewPager>
-
-
<RelativeLayout
-
android:layout_width="wrap_content"
-
android:layout_height="50dp"
-
android:layout_alignParentBottom="true"
-
android:layout_centerHorizontal="true" >
-
-
<ImageView
-
android:id="@+id/point_1"
-
android:layout_width="10dp"
-
android:layout_height="10dp"
-
android:layout_centerVertical="true"
-
android:background="@drawable/music_zone_indicator_current" />
-
-
<ImageView
-
android:id="@+id/point_2"
-
android:layout_width="10dp"
-
android:layout_height="10dp"
-
android:layout_centerVertical="true"
-
android:layout_marginLeft="10dp"
-
android:layout_toRightOf="@+id/point_1"
-
android:background="@drawable/music_zone_indicator_common" />
-
-
<ImageView
-
android:id="@+id/point_3"
-
android:layout_width="10dp"
-
android:layout_height="10dp"
-
android:layout_centerVertical="true"
-
android:layout_marginLeft="10dp"
-
android:layout_toRightOf="@+id/point_2"
-
android:background="@drawable/music_zone_indicator_common" />
-
-
<ImageView
-
android:id="@+id/point_4"
-
android:layout_width="10dp"
-
android:layout_height="10dp"
-
android:layout_centerVertical="true"
-
android:layout_marginLeft="10dp"
-
android:layout_toRightOf="@+id/point_3"
-
android:background="@drawable/music_zone_indicator_common" />
-
</RelativeLayout>
-
- </RelativeLayout>
添加 GuideFragment 來實現界面
-
package com.happy.fragment;
-
-
import android.content.Intent;
-
import android.graphics.Color;
-
import android.os.AsyncTask;
-
import android.os.Bundle;
-
import android.os.Handler;
-
import android.os.Message;
-
import android.support.v4.app.Fragment;
-
import android.view.LayoutInflater;
-
import android.view.View;
-
import android.view.View.OnClickListener;
-
import android.view.ViewGroup;
-
import android.view.animation.Animation;
-
import android.view.animation.LinearInterpolator;
-
import android.view.animation.TranslateAnimation;
-
import android.widget.ImageView;
-
import android.widget.RelativeLayout;
-
import android.widget.TextView;
-
-
import com.happy.common.Constants;
-
import com.happy.ui.MainActivity;
-
import com.happy.ui.R;
-
import com.happy.util.DataUtil;
-
-
public class GuideFragment extends Fragment {
-
private View mMainView;
-
-
/**
-
* 初始化後執行動畫
-
*/
-
private boolean isInitAni = false;
-
/**
-
* 是否有動畫
-
*/
-
private boolean hasAni = false;
-
-
/**
-
* 背景
-
*/
-
private RelativeLayout parentRelativeLayout;
-
private int color = Color.rgb(163, 161, 212);
-
-
/**
-
* 主標題
-
*/
-
private TextView mainTitleTextView;
-
/**
-
* 主標題內容
-
*/
-
private String mainText;
-
-
/**
-
* 右到左標題動畫
-
*/
-
private TranslateAnimation rightToLeftTranslateAnimation;
-
/**
-
* 左到右標題動畫
-
*/
-
private TranslateAnimation leftToRightTranslateAnimation;
-
-
/**
-
* 副標題
-
*/
-
private TextView secondTitleTextView;
-
/**
-
* 副標題內容
-
*/
-
private String secondText;
-
-
/**
-
* 中部圖片
-
*/
-
private ImageView centPICImageView;
-
private int centPICImage = R.drawable.guide_first_person;
-
-
/**
-
* 底部按鈕圖片
-
*/
-
private ImageView goToImageView;
-
/**
-
* 是否可視
-
*/
-
private boolean visibility = false;
-
-
public GuideFragment() {
-
-
}
-
-
@Override
-
public void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
initComponent();
-
}
-
-
@Override
-
public View onCreateView(LayoutInflater inflater, ViewGroup container,
-
Bundle savedInstanceState) {
-
ViewGroup viewGroup = (ViewGroup) mMainView.getParent();
-
if (viewGroup != null) {
-
viewGroup.removeAllViewsInLayout();
-
}
-
return mMainView;
-
}
-
-
private void initComponent() {
-
LayoutInflater inflater = getActivity().getLayoutInflater();
-
mMainView = inflater.inflate(R.layout.fragement_guide, null, false);
-
-
// 背景圖片
-
parentRelativeLayout = (RelativeLayout) mMainView
-
.findViewById(R.id.parent);
-
parentRelativeLayout.setBackgroundColor(color);
-
-
// 主標題
-
mainTitleTextView = (TextView) mMainView.findViewById(R.id.main_title);
-
mainTitleTextView.setText(mainText);
-
mainTitleTextView.setVisibility(View.INVISIBLE);
-
-
// 副標題
-
secondTitleTextView = (TextView) mMainView
-
.findViewById(R.id.second_title);
-
secondTitleTextView.setText(secondText);
-
secondTitleTextView.setVisibility(View.INVISIBLE);
-
-
// 中部圖片
-
centPICImageView = (ImageView) mMainView.findViewById(R.id.center_pic);
-
centPICImageView.setBackgroundResource(centPICImage);
-
-
// 跳轉按鈕
-
goToImageView = (ImageView) mMainView.findViewById(R.id.goTo);
-
if (visibility) {
-
goToImageView.setVisibility(View.VISIBLE);
-
} else {
-
goToImageView.setVisibility(View.INVISIBLE);
-
}
-
-
goToImageView.setOnClickListener(new ItemOnClick());
-
-
// 右到左動畫
-
-
rightToLeftTranslateAnimation = new TranslateAnimation(
-
Animation.RELATIVE_TO_PARENT, +1.0f,
-
Animation.RELATIVE_TO_PARENT, 0.0f,
-
Animation.RELATIVE_TO_PARENT, 0.0f,
-
Animation.RELATIVE_TO_PARENT, 0.0f);
-
rightToLeftTranslateAnimation.setInterpolator(new LinearInterpolator());
-
rightToLeftTranslateAnimation.setFillAfter(true);
-
rightToLeftTranslateAnimation.setDuration(1000);
-
-
// 左到右動畫
-
leftToRightTranslateAnimation = new TranslateAnimation(
-
Animation.RELATIVE_TO_PARENT, -1.0f,
-
Animation.RELATIVE_TO_PARENT, 0.0f,
-
Animation.RELATIVE_TO_PARENT, 0.0f,
-
Animation.RELATIVE_TO_PARENT, 0.0f);
-
-
leftToRightTranslateAnimation.setInterpolator(new LinearInterpolator());
-
leftToRightTranslateAnimation.setFillAfter(true);
-
leftToRightTranslateAnimation.setDuration(1000);
-
-
if (isInitAni) {
-
startAnimation();
-
}
-
}
-
-
/**
-
* 開始動畫
-
*/
-
private void startAnimation() {
-
new AsyncTask<String, Integer, String>() {
-
-
@Override
-
protected String doInBackground(String... params) {
-
try {
-
Thread.sleep(100);
-
} catch (InterruptedException e) {
-
e.printStackTrace();
-
}
-
startTitleAnimation(true);
-
return null;
-
}
-
-
}.execute("");
-
}
-
-
/**
-
* 設置背景顏色
-
*
-
* @param color
-
*/
-
public void setParentRelativeLayoutColor(int color) {
-
this.color = color;
-
}
-
-
/**
-
* 設置底部按鈕是否可視
-
*
-
* @param visibility
-
*/
-
public void setGoToImageViewVisibility(boolean visibility) {
-
this.visibility = visibility;
-
}
-
-
/**
-
* 設置主標題內容
-
*
-
* @param mainText
-
* 主標題內容
-
*/
-
public void setMainTitleText(String mainText) {
-
this.mainText = mainText;
-
}
-
-
/**
-
* 設置副標題內容
-
*
-
* @param secondText
-
* 副標題內容
-
*/
-
public void setSecondTitleText(String secondText) {
-
this.secondText = secondText;
-
}
-
-
/**
-
* 設置中部圖片
-
*
-
* @param centPICImage
-
*/
-
public void setCentPICImage(int centPICImage) {
-
this.centPICImage = centPICImage;
-
}
-
-
private Handler mHandler = new Handler() {
-
-
@Override
-
public void handleMessage(Message msg) {
-
if (hasAni) {
-
mainTitleTextView.clearAnimation();
-
secondTitleTextView.clearAnimation();
-
}
-
boolean isRightToLeft = (Boolean) msg.obj;
-
if (isRightToLeft) {
-
mainTitleTextView.startAnimation(rightToLeftTranslateAnimation);
-
secondTitleTextView
-
.startAnimation(rightToLeftTranslateAnimation);
-
} else {
-
mainTitleTextView.startAnimation(leftToRightTranslateAnimation);
-
secondTitleTextView
-
.startAnimation(leftToRightTranslateAnimation);
-
}
-
hasAni = true;
-
}
-
-
};
-
-
/**
-
* 設置標題動畫
-
*
-
* @param isRightToLeft
-
*/
-
public void startTitleAnimation(boolean isRightToLeft) {
-
Message msg = new Message();
-
msg.obj = isRightToLeft;
-
mHandler.sendMessage(msg);
-
}
-
-
/**
-
* 設置動畫
-
*
-
* @param isInitAni
-
*/
-
public void setInitAni(boolean isInitAni) {
-
this.isInitAni = isInitAni;
-
}
-
-
/**
-
* 停止動畫
-
*/
-
public void stopAnimation() {
-
if (mainTitleTextView != null && secondTitleTextView != null) {
-
if (hasAni) {
-
mainTitleTextView.clearAnimation();
-
secondTitleTextView.clearAnimation();
-
mainTitleTextView.setVisibility(View.INVISIBLE);
-
secondTitleTextView.setVisibility(View.INVISIBLE);
-
hasAni = false;
-
}
-
}
-
}
-
-
class ItemOnClick implements OnClickListener {
-
-
@Override
-
public void onClick(View v) {
-
switch (v.getId()) {
-
case R.id.goTo:
-
goHome();
-
break;
-
}
-
}
-
-
/**
-
* 跳轉到主頁面
-
*/
-
private void goHome() {
-
// 設置是否是第一次運行參數
-
DataUtil.saveValue(getActivity(), Constants.ISFIRST_KEY, false);
-
Intent intent = new Intent(getActivity(), MainActivity.class);
-
startActivity(intent);
-
// 添加界面切換效果,注意只有Android的2.0(SdkVersion版本號爲5)以後的版本才支持
-
int version = Integer.valueOf(android.os.Build.VERSION.SDK);
-
if (version >= 5) {
-
getActivity().overridePendingTransition(R.anim.anim_in,
-
R.anim.anim_out);
-
}
-
getActivity().finish();
-
}
-
}
-
-
}
-
<?xml version="1.0" encoding="utf-8"?>
-
<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="fill_parent"
-
tools:context=".GuideFragment" >
-
-
<RelativeLayout
-
android:id="@+id/parent"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent" >
-
-
<RelativeLayout
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent"
-
android:layout_marginBottom="50dp" >
-
-
<TextView
-
android:id="@+id/main_title"
-
android:layout_width="200dp"
-
android:layout_height="wrap_content"
-
android:layout_centerHorizontal="true"
-
android:layout_marginBottom="5dp"
-
android:layout_marginTop="30dp"
-
android:gravity="center_horizontal"
-
android:text="主標題"
-
android:textColor="#ffffff"
-
android:textSize="45dp" />
-
-
<TextView
-
android:id="@+id/second_title"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:layout_below="@+id/main_title"
-
android:layout_centerHorizontal="true"
-
android:layout_marginBottom="5dp"
-
android:layout_marginTop="5dp"
-
android:gravity="center_horizontal"
-
android:text="副標題"
-
android:textColor="#ffffff"
-
android:textSize="30dp" />
-
-
<ImageView
-
android:id="@+id/center_pic"
-
android:layout_width="250dp"
-
android:layout_height="250dp"
-
android:layout_above="@+id/goTo"
-
android:layout_below="@+id/second_title"
-
android:layout_centerHorizontal="true"
-
android:layout_marginBottom="10dp"
-
android:layout_marginTop="10dp" />
-
-
<ImageView
-
android:id="@+id/goTo"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:layout_alignParentBottom="true"
-
android:layout_centerHorizontal="true"
-
android:layout_marginBottom="5dp"
-
android:layout_marginTop="5dp"
-
android:background="@drawable/guide_goto"
-
android:clickable="true" />
-
</RelativeLayout>
-
</RelativeLayout>
-
- </RelativeLayout>
差點 忘記了 ActivityManage 類 處理activity
-
package com.happy.manage;
-
-
import java.util.LinkedList;
-
import java.util.List;
-
-
import android.app.Activity;
-
-
/**
-
* activity的管理:退出時,遍歷所有的activity,並finish,最後退出系統。
-
*
-
* @author Administrator 最近修改時間2013年12月10日
-
*/
-
public class ActivityManage {
-
-
/**
-
* activity列表
-
*/
-
private List<Activity> activityList = new LinkedList<Activity>();
-
private static ActivityManage instance = null;
-
-
private ActivityManage() {
-
-
}
-
-
public static ActivityManage getInstance() {
-
if (instance == null) {
-
instance = new ActivityManage();
-
}
-
return instance;
-
}
-
-
/**
-
* 添加
-
*
-
* @param activity
-
*/
-
public void addActivity(Activity activity) {
-
activityList.add(activity);
-
}
-
-
/**
-
* 退出
-
*/
-
public void exit() {
-
for (Activity activity : activityList) {
-
if (!activity.isFinishing() && activity != null) {
-
activity.finish();
-
}
-
}
-
int id = android.os.Process.myPid();
-
if (id != 0) {
-
android.os.Process.killProcess(id);
-
}
-
}
-
}