源码地址: 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;
-
}
-
复制代码
添加一个类 DataUtil 来处理 SharedPreferences 配置文件的内容
-
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;
-
-
}
-
}
-
复制代码
修改 SplashActivity 的内容
-
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();
-
}
-
}
-
复制代码
添加 GuideActivity 引导页面
-
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);
-
}
-
}
-
复制代码
GuideActivity 的布局文件 activity_guide
-
<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>
复制代码
引导界面 这里用 viewpager 来实现
添加 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();
-
}
-
}
-
-
}
-
复制代码
GuideFragment 布局文件 fragement_guide
-
<?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);
-
}
-
}
-
}
-
复制代码
乐乐音乐播放器(三) 第一次引导页面
原文:http://blog.csdn.net/aakzhangliangming/article/details/45732583