Android App 第一次打开时的引导界面

Android App 第一次打开时的引导界面,这个需求是非常多的。在写新项目的时候,刚好要用到,在网上找了一下 demo,没发现非满意的。所以只好自己动手写一个,分享一下,避免以后大家重复造轮子。效果图如下(虽然有点丑)

上面这个就是引导界面 GuideActivity 的界面了,实现思路很简单:主界面用 FrameLayout 布局,后面用 ViewPager 装载图片。下面几个小点指示当前滑动到哪个界面了,因为没现在的控制可用,所以自定义了一个 InidcatorView,布局文件如下

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <cn.guide.IndicatorView
        android:id="@+id/indicatorView"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:layout_marginBottom="30dp"
        android:layout_gravity="bottom|center_horizontal"/>
</FrameLayout>

自定义的 IndicatorView 代码如下

public class IndicatorView extends View{

private static final String LOG_TAG = IndicatorView.class.getName();    private int mCurrentIndicatorIndex = 0;    private int mIndicatorCount = 4;    private int mIndicatorDistance = 30; // 圆点之间的距离(圆心距)    private int mStartDotX;    private int mDotY;    private Paint mPaint;

public IndicatorView(Context context) {        super(context, null);    }

public IndicatorView(Context context, AttributeSet attrs){        super(context, attrs);        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);        mPaint.setStyle(Paint.Style.FILL);    }

@Override    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){

int viewWidth = MeasureSpec.getSize(widthMeasureSpec);        int viewHeight = MeasureSpec.getSize(heightMeasureSpec);

int drawWidth = (mIndicatorCount + 1) * mIndicatorDistance;        mStartDotX = (viewWidth - drawWidth) / 2;        mDotY = viewHeight / 2;

setMeasuredDimension(viewWidth, viewHeight) ;    }

@Override    protected void onDraw(Canvas canvas) {        super.onDraw(canvas);

float currentDotX = mStartDotX;        for(int i = 0; i < mIndicatorCount; i++) {

currentDotX += mIndicatorDistance;            if(i == mCurrentIndicatorIndex) {                mPaint.setColor(0x7fff0000);            } else {                mPaint.setColor(0x7f0000ff);            }            canvas.drawCircle(currentDotX, mDotY, 10, mPaint);        }    }

public void setIndicatorCount(int count) {        mIndicatorCount = count;    }

public void setCurIndicatorIndex(int index) {        mCurrentIndicatorIndex = index;        invalidate();    }}

setIndicatorCount 用来设置总共有多少个点,引导界面要加载多少张图,setIndicatorCount 的参数就设置成多少就可以了。setCurIndicatorIndex 用来设置当前滑动到哪个点上了,顺便刷新界面。因为比较简单,所以就不做太多介绍了

点击下载源码

时间: 2024-08-03 11:35:35

Android App 第一次打开时的引导界面的相关文章

android实现应用程序只有在第一次启动时显示引导界面

概述 SharedPreferences的使用非常简单,能够轻松的存放数据和读取数据.SharedPreferences只能保存简单类型的数据,例如,String.int等.一般会将复杂类型的数据转换成Base64编码,然后将转换后的数据以字符串的形式保存在 XML文件中,再用SharedPreferences保存. 使用SharedPreferences保存key-value对的步骤如下: (1)使用Activity类的getSharedPreferences方法获得SharedPrefere

android应用程序第一次启动时显示引导界面

市面上好多优秀的应用(举例新浪微博.UC浏览器)都采用了欢迎页面与使用向导的方式给用户带来了良好的用户体验. 一般来说用户第一次安装应用或者安装了新版本后第一次进入应用都会显示成 欢迎页面-使用向导-主界面 的方式 用户没有安装新版本或者不是第一次进入的时候都会显示成 欢迎页面-主界面的方式 想要实现这种不同的分支,我们就要使用一种变量来存储我们是否是第一次进入应用,当然这种变量不可能是存储在应用里,而是要存储在应用包名底下的文件中 那么我们就来看看实现这种变量存储和修改的步骤吧 1.在应用的欢

Android应用第一次启动时的欢迎界面制作

原理是这样,我们在SharedPreferences中存储一个int型数据,用来代表第几次登录,每次启动时都读取出来判断是不是第一次启动,然后依次判断是否要显示欢迎界面, 具体实现如下: 设置一个欢迎界面的Activity,并设置为主Activity,在判断第几次启动后来决定要不要跳转到MainActivity package com.example.f; import androidx.appcompat.app.AppCompatActivity; import android.conten

excel 2007第一次打开时显示there was a problem sending command to the program,再打开一次就能打开了。

excel 2007第一次打开时总是显示there was a problem sending command to the program. 关闭后打开一次就能打开了. 由于装的东西太多,初步怀疑是兼容性的问题. 在Excel option里面的add-in 和 trusted publisher 里面去掉非office的插件. 如下图: 保存后,再次打开, 问题解决. excel 2007第一次打开时显示there was a problem sending command to the p

Android应用第一次打开,引导界面的实现

转载请注明出处,谢谢http://blog.csdn.net/harryweasley/article/details/42079167 先说下思路:1.利用Preference存储数据,来记录是否是第一次打开软件 2.利用ViewPager实现几个图片之间的切换,在每个图片下方用代码画圆圈,圆圈会跟着图片的改变而改变. 3.在最后一张图片,添加button点击事件,进入正式界面. 程序虽然很简单,但是很实用. 看下效果图: 我们会看到圆圈的点会根据图片改变而改变. 下面开始讲解: 首先是act

安装系统时,引导界面部分隐藏导致不能进行下一步的问题

1.场景: 本人新手,想要入手Linux系统,听说Zorin OS是由Win7转向Linux的最佳选择,于是就制作了usb启动盘进行安装,安装引导界面前几步还好,但到了分区界面出现了令人捉急的问题. 2.问题: 分区界面一部分隐藏在屏幕之外,无法进行下一步操作,界面显示如下图所示. 3.解决: 到此步时,按 Alt + F7 即可移动当前界面的位置.这个方法是找了好久最后在 Stack Overflow 上找到的.解决方法如下图所示: 解决后的效果如下图所示:

Android APP唤醒打开其他APP

App(a):判断是否为App(b)是否存在,不存在选择下载 存在后台状态直接唤醒 否则直接打开App(a)部分代码 if (checkPackage("com.xxx.android")) { if (ToolsUtils.isBackgroundRunning(this, "com.xxx.android")) { Intent intent = new Intent(); intent.setPackage("com.xxx.android"

使用UIPageControl UIScrollView制作APP引导界面

1. 新建两个视图控制器类(继承自UIViewController), 在AppDelegate.m中指定根视图控制器 #import "AppDelegate.h" #import "RootViewController.h" #import "LeadViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (void)dealloc { se

android——利用SharedPreference做引导界面

很久以前就接触过sharedPreference这个android中的存储介质.但是一直没有实际使用过,今天在看之前做的“民用机型大全”的app时,突然想到可以使用sharedPreference类来改进这个app中的一个缺陷. 此前,我先介绍sharedPreference的使用.Android数据总共有四种存储的方式 一.SharePreference 二.SQLite 三.File 四.ContentProvider SharedPreference类是一个轻量级的存储类,特别适合保存软件