Android之应用首次使用的欢迎界面实例_第1张图片Android之应用首次使用的欢迎界面实例_第2张图片

关键代码如下:

package com.chinaideal.bkclient.tabmain;import java.util.ArrayList;import java.util.List;import android.app.Activity;import android.content.Context;import android.content.Intent;import android.content.SharedPreferences;import android.content.SharedPreferences.Editor;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.support.v4.view.ViewPager;import android.support.v4.view.ViewPager.OnPageChangeListener;import android.view.View;import android.view.ViewGroup;import android.view.ViewTreeObserver.OnPreDrawListener;import android.view.animation.TranslateAnimation;import android.widget.ImageView;import android.widget.ImageView.ScaleType;public class WelComeActivity extends Activity {// 首次使用程序的显示的欢迎图片private int[] ids = { R.drawable.webcom_frist_image,R.drawable.webcom_two_image, R.drawable.webcom_three_image,R.drawable.niwodai_welcom };SharedPreferences share;private List<View> guides = new ArrayList<View>();private ViewPager pager;private ImageView curDot;// 位移量private int offset;// 记录当前的位置private int curPos = 0;Editor editor;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);share = getSharedPreferences("showWelcomm", Context.MODE_PRIVATE);editor = share.edit();// 判断是否首次登录程序if (share.contains("shownum")) {setContentView(R.layout.welcomniwo);int num = share.getInt("shownum", 0);editor.putInt("shownum", num++);editor.commit();skipActivity(1);} else {editor.putInt("shownum", 1);editor.commit();setContentView(R.layout.welcometabx);initView();}}private void initView() {for (int i = 0; i < ids.length; i++) {ImageView iv = new ImageView(this);iv.setImageResource(ids[i]);ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);iv.setLayoutParams(params);iv.setScaleType(ScaleType.FIT_XY);guides.add(iv);}curDot = (ImageView) findViewById(R.id.cur_dot);curDot.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {public boolean onPreDraw() {offset = curDot.getWidth();return true;}});WecommPagerAdapter adapter = new WecommPagerAdapter(guides);pager = (ViewPager) findViewById(R.id.showwelom_page);pager.setAdapter(adapter);pager.setOnPageChangeListener(new OnPageChangeListener() {public void onPageSelected(int arg0) {moveCursorTo(arg0);if (arg0 == ids.length - 1) {// 到最后一张了skipActivity(2);}curPos = arg0;}public void onPageScrolled(int arg0, float arg1, int arg2) {}public void onPageScrollStateChanged(int arg0) {}});}/** * 移动指针到相邻的位置 *  * @param position *            指针的索引值 * */private void moveCursorTo(int position) {TranslateAnimation anim = new TranslateAnimation(offset * curPos,offset * position, 0, 0);anim.setDuration(300);anim.setFillAfter(true);curDot.startAnimation(anim);}/** * 延迟多少秒进入主界面 * @param min 秒 */private void skipActivity(int min) {new Handler().postDelayed(new Runnable() {@Overridepublic void run() {Intent intent = new Intent(WelComeActivity.this,TabHostMain.class);startActivity(intent);WelComeActivity.this.finish();}}, 1000*min);}}

public class WecommPagerAdapter extends PagerAdapter{private List<View> views;public GuidePagerAdapter(List<View> views){this.views=views;}@Overridepublic void destroyItem(View arg0, int arg1, Object arg2) {((ViewPager) arg0).removeView(views.get(arg1));}@Overridepublic void finishUpdate(View arg0) {}@Overridepublic int getCount() {return views.size();}@Overridepublic Object instantiateItem(View arg0, int arg1) {((ViewPager) arg0).addView(views.get(arg1), 0);return views.get(arg1);}@Overridepublic boolean isViewFromObject(View arg0, Object arg1) {return arg0 == (arg1);}@Overridepublic void restoreState(Parcelable arg0, ClassLoader arg1) {}@Overridepublic Parcelable saveState() {return null;}@Overridepublic void startUpdate(View arg0) {}}


<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <android.support.v4.view.ViewPager        android:id="@+id/showwelom_page"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:layout_gravity="center"        android:flipInterval="30"        android:persistentDrawingCache="animation" />    <FrameLayout        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentBottom="true"        android:layout_centerHorizontal="true"        android:gravity="center"         android:paddingBottom="22.0dip">        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:gravity="center"            android:orientation="horizontal" >            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_weight="1.0"                android:src="@drawable/dot1_w" />            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_weight="1.0"                android:src="@drawable/dot1_w" />            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_weight="1.0"                android:src="@drawable/dot1_w" />            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_weight="1.0"                android:src="@drawable/dot1_w" />         </LinearLayout>        <ImageView            android:id="@+id/cur_dot"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:src="@drawable/dot2_w" />    </FrameLayout></RelativeLayout>



更多相关文章

  1. Android界面编程——Android高级UI组件(三)
  2. android 图片旋转
  3. android 笔记 --- Android界面刷新的方法
  4. Android 深入解析用户界面(一)
  5. android基础学习--->Android SharedPreferences存储对象和图片(An
  6. Android根据Button状态(normal,focused,pressed)显示不同背景图
  7. Android 高清加载巨图方案 拒绝压缩图片
  8. Android异步机制一:使用Thread+Handler实现非UI线程更新UI界面
  9. Android图片加载神器之Fresco,基于各种使用场景的讲解

随机推荐

  1. Android FileProvider应用之间共享数据
  2. Android 4.4 meminfo 实现分析
  3. 2011年linux数据库的android在线分享
  4. Android Studio 第一次新建Android Gradl
  5. [Android] 内存泄漏调试经验分享 (一)
  6. android 两个应用之间的通信与调用
  7. android 无线启动过程分析
  8. android源代码的利用
  9. Android ListView城市列表,按a-z分组字母
  10. 我的android开发学习之路