Android 新手引导
关于这个Demo的写法很多 我也献上一段 效果图如下
上代码
MainActivity
public class MainActivity extends Activity { // public List<File> Localphotos_List = new ArrayList<File>();
private static final int[] pics = { R.drawable.guide1, R.drawable.guide2, R.drawable.guide3, R.drawable.guide4, R.drawable.guide5 }; private ViewPager mViewPager;
private ImageView mPage0;
private ImageView mPage1;
private ImageView mPage2;
private ImageView mPage3;
private ImageView mPage4;
private Button start_bn; private boolean isFirste; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main); // getPhotos(); // isFirste =
// SharedPreferencesUtils.getFirstLoginState(this.getApplicationContext()); mViewPager = (ViewPager) findViewById(R.id.whatsnew_viewpager);
start_bn = (Button) findViewById(R.id.start_bn);
start_bn.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) { }
}); mViewPager.setOnPageChangeListener(new MyOnPageChangeListener()); mPage0 = (ImageView) findViewById(R.id.page0);
mPage1 = (ImageView) findViewById(R.id.page1);
mPage2 = (ImageView) findViewById(R.id.page2);
mPage3 = (ImageView) findViewById(R.id.page3);
mPage4 = (ImageView) findViewById(R.id.page4); final ArrayList<ImageView> list = new ArrayList<ImageView>();
// 初始化引导图片列表
for (int i = 0; i < pics.length; i++) {
ImageView iv = new ImageView(this);
iv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
iv.setImageResource(pics[i]);
iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
list.add(iv);
} /*
* if (isFirste) { mPage3.setVisibility(View.VISIBLE); list.add(view4); }
* else { mPage3.setVisibility(View.GONE); }
*/ PagerAdapter adapter = new PagerAdapter() { @Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
} @Override
public int getCount() {
return list.size();
} @Override
public void destroyItem(View container, int position, Object object) {
((ViewPager) container).removeView(list.get(position));
} @Override
public Object instantiateItem(View container, int position) {
((ViewPager) container).addView(list.get(position));
return list.get(position);
}
}; mViewPager.setAdapter(adapter);
} public class MyOnPageChangeListener implements OnPageChangeListener { @Override
public void onPageScrollStateChanged(int arg0) { } @Override
public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override
public void onPageSelected(int arg0) {
switch (arg0) {
case 0:
display();
mPage0.setImageDrawable(getResources().getDrawable(R.drawable.page_now));
mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page));
mPage2.setImageDrawable(getResources().getDrawable(R.drawable.page));
mPage3.setImageDrawable(getResources().getDrawable(R.drawable.page));
mPage4.setImageDrawable(getResources().getDrawable(R.drawable.page));
break; case 1:
display();
mPage0.setImageDrawable(getResources().getDrawable(R.drawable.page));
mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page_now));
mPage2.setImageDrawable(getResources().getDrawable(R.drawable.page));
mPage3.setImageDrawable(getResources().getDrawable(R.drawable.page));
mPage4.setImageDrawable(getResources().getDrawable(R.drawable.page));
break; case 2:
display();
mPage0.setImageDrawable(getResources().getDrawable(R.drawable.page));
mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page));
mPage2.setImageDrawable(getResources().getDrawable(R.drawable.page_now));
mPage3.setImageDrawable(getResources().getDrawable(R.drawable.page));
mPage4.setImageDrawable(getResources().getDrawable(R.drawable.page));
break; case 3:
display();
mPage0.setImageDrawable(getResources().getDrawable(R.drawable.page));
mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page));
mPage2.setImageDrawable(getResources().getDrawable(R.drawable.page));
mPage3.setImageDrawable(getResources().getDrawable(R.drawable.page_now));
mPage4.setImageDrawable(getResources().getDrawable(R.drawable.page)); /* mPage3.setVisibility(View.GONE);
mPage0.setVisibility(View.GONE);
mPage1.setVisibility(View.GONE);
mPage2.setVisibility(View.GONE);*/ /*
* SharedPreferencesUtils.saveFirstLoginState(Activity_WhatsNew.this.
* getApplicationContext()); File dbFile = new
* File(ResourceManager.DBDIR_PATH + "/userprofiledb.db"); if
* (!dbFile.exists()) { UserProfileDB.instance().createNew(); } new
* Handler().postDelayed(new Runnable() { public void run() {
* startActivity(new Intent(Activity_WhatsNew.this,
* Activity_LoginForFirst.class)); finish(); } }, 500);
*/
break; case 4:
/* mPage0.setImageDrawable(getResources().getDrawable(R.drawable.page));
mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page));
mPage2.setImageDrawable(getResources().getDrawable(R.drawable.page));
mPage3.setImageDrawable(getResources().getDrawable(R.drawable.page));
mPage4.setImageDrawable(getResources().getDrawable(R.drawable.page_now));*/
hide();
break;
}
}
} private void hide() {
mPage0.setVisibility(View.GONE);
mPage1.setVisibility(View.GONE);
mPage2.setVisibility(View.GONE);
mPage3.setVisibility(View.GONE);
mPage4.setVisibility(View.GONE);
start_bn.setVisibility(View.VISIBLE);
} private void display() {
mPage0.setVisibility(View.VISIBLE);
mPage1.setVisibility(View.VISIBLE);
mPage2.setVisibility(View.VISIBLE);
mPage3.setVisibility(View.VISIBLE);
mPage4.setVisibility(View.VISIBLE);
start_bn.setVisibility(View.GONE);
} }
activity_main
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical" > <android.support.v4.view.ViewPager
android:id="@+id/whatsnew_viewpager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" >
</android.support.v4.view.ViewPager> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="30dp"
android:gravity="center_horizontal" > <ImageView
android:id="@+id/page0"
android:layout_width="10dp"
android:layout_height="10dp"
android:background="@drawable/page_now" /> <ImageView
android:id="@+id/page1"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginLeft="10dp"
android:background="@drawable/page" /> <ImageView
android:id="@+id/page2"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginLeft="10dp"
android:background="@drawable/page" /> <ImageView
android:id="@+id/page3"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginLeft="10dp"
android:background="@drawable/page" /> <ImageView
android:id="@+id/page4"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginLeft="10dp"
android:background="@drawable/page" />
</LinearLayout>
</LinearLayout> <Button
android:id="@+id/start_bn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="40dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:text="马上开始"
android:visibility="gone"
/> </FrameLayout>
Demo见github
https://github.com/huanyi0723/NoviceGuide
Android 新手引导的更多相关文章
- Android新手引导库推荐
本文同步至http://javaexception.com/archives/31 介绍一波新手引导层的库.都是star数挺高的一些库. 1.NewbieGuide(国内开发者开发) Android ...
- 59.Android开源项目及库 (转)
转载 : https://github.com/Tim9Liu9/TimLiu-Android?hmsr=toutiao.io&utm_medium=toutiao.io&utm_so ...
- 各种Android UI开源框架 开源库
各种Android UI开源框架 开源库 转 https://blog.csdn.net/zhangdi_gdk2016/article/details/84643668 自己总结的Android开源 ...
- android打飞机游戏、MVP句子迷App、悬浮窗、RxJava+Retrofit、加载动画、定制计划App等源码
Android精选源码 微信打飞机 android进度设置加载效果源码 Android新手引导库EasyGuide MVP-好看又好用的句子迷客户端 XFloatView 一个简易的悬浮窗实现方案 a ...
- android文件选择器、仿淘宝编辑页面、新手引导层等源码
Android精选源码 单片机和安卓应用,传感器 文件选择器 android滑动选择的尺子view源码 android视频录制 视频压缩的源码 仿今日头条顶部导航指示器源码 Android框架+常用控 ...
- Android开发之ViewPager做新手引导界面
先看一下我们要开发的界面(三张图片,滑到最后一个会出现开始体验的Button,下面的小红点会跟着一起滑动): 首先看一下布局文件: <?xml version="1.0" e ...
- Android开发工具之Dash
作为一名死coder,每天最常见的动作就是查看各种API文档,你一定也有过同时打开N个窗口(HTML.PDF.CHM),不停的在编辑器与文档之间切换的感受吧?怎么说呢,其实我很讨厌这种枯燥无味的动作, ...
- Android主流UI开源库整理(转载)
http://www.jianshu.com/p/47a4a7b99364 标题隐含了两个层面的意思,一个是主流,另一个是UI.主流既通用,一些常规的按钮.Switch.进度条等控件都是通用控件,因此 ...
- android 项目学习随笔二(引导页 )
1.引导页 1.定义灰色.红色圆点的shape XML文件 2.定义布局文件,利用相对布局文件定位,利用线性布局加载灰色圆点,imageview加载红色圆点 3.android.support.v4. ...
随机推荐
- ACM第四站————最小生成树(普里姆算法)
对于一个带权的无向连通图,其每个生成树所有边上的权值之和可能不同,我们把所有边上权值之和最小的生成树称为图的最小生成树. 普里姆算法是以其中某一顶点为起点,逐步寻找各个顶点上最小权值的边来构建最小生成 ...
- ACM题目————STL练习之Ananagrams
Description Most crossword puzzle fans are used to anagrams--groups of words with the same letters i ...
- js笔记---(运动)通用的move方法,兼容透明度变化
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- JSONArray传值的使用小结
今天使用了SpringMVC+mybatis传值.从controller中传到service中.可是由于版本问题参数中不能有大写和下划线,在service中只能用String 来接受json字符串.接 ...
- c#之双色球
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 【20160924】GOCVHelper 图像增强部分(4)
//使得rect区域半透明 Mat translucence(Mat src,Rect rect,int idepth){ Mat dst = src.clone(); ...
- vi编辑文件E437: terminal capability "cm" required 解决办法
E437: terminal capability "cm" required 这个错误一般是环境变量TERM没有配置或者配置错误所致. 解决办法: 执行export TERM=x ...
- 2016年12月9日 星期五 --出埃及记 Exodus 21:4
2016年12月9日 星期五 --出埃及记 Exodus 21:4 If his master gives him a wife and she bears him sons or daughters ...
- 向sql server 导入数据库
在sql server 中选择数据库.右键,还原数据库 选择源设备,点击添加,选中相应的数据库文件. 在目标数据库栏选择相应的数据库名称 点击下一步.
- Java-基础编程(螺旋矩阵&乘法表)
package cn.rick.study; import java.io.BufferedReader;import java.io.InputStreamReader;import java.ut ...