AndroidUI 引导页面的使用
一个应用程序都少不了欢迎页面和引导页面,本文主要讲如何制作一个引页面;
首页所有的目录结构:
新建Welcome引导页面和Activity:
<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=".MainActivity" > <ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/welcome_android"/>
</RelativeLayout>
import android.app.Activity;
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; //进入APP后的第一个欢迎页面
//欢迎页面实现如果是首次运行APP的话,将页面延时2秒后,跳转到到引导页,如果不是第一次加载的话
//则跳到主页面
public class Welcome extends Activity { private Boolean isFirstIn=false;
private static final int GO_HOME=1000;
private static final int GO_GUIDE=1001;
private static final int TIME=2000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
init();
} private void init(){
SharedPreferences shared=getSharedPreferences("rock", MODE_PRIVATE);
//getBoolean 第二个参数defValue:如果Key在shared中不存在的话返回defValue
isFirstIn=shared.getBoolean("isFirstIn", true);
if(!isFirstIn){
// 延时2秒发送消息
myHandelr.sendEmptyMessageDelayed(GO_HOME, TIME);
}else{
//首次加载,保存加载记录并跳转到引导页
myHandelr.sendEmptyMessageDelayed(GO_GUIDE, TIME);
Editor editor=shared.edit();
editor.putBoolean("isFirstIn", false);
editor.commit();
} } //消息的处理者,handler负责将需要传递的信息封装成Message,通过调用handler对象的obtainMessage()来实现;
//将消息传递给Looper,这是通过handler对象的sendMessage()来实现的
private Handler myHandelr=new Handler(){
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case GO_HOME:
goHome();
break;
case GO_GUIDE:
goGuide();
break;
}
}
};
private void goGuide() {
Intent i=new Intent(Welcome.this,Guide.class);
startActivity(i);
finish();
}
private void goHome() {
Intent i=new Intent(Welcome.this,MainActivity.class);
startActivity(i);
finish();
}
}
然后是引导页面和引导页面的activity:
guide.xml:
<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=".MainActivity" > <android.support.v4.view.ViewPager
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/viewPager1"
android:background="#00000000">
</android.support.v4.view.ViewPager>
<!-- 引导页面导航按钮 -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:layout_alignParentBottom="true"> <ImageView android:id="@+id/iv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/login_point_selected"/>
<ImageView android:id="@+id/iv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/login_point"/>
<ImageView android:id="@+id/iv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/login_point"/>
</LinearLayout>
</RelativeLayout>
one.xml
<LinearLayout 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=".MainActivity" > <ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/guide_1"/>
</LinearLayout>
two.xml:
<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=".MainActivity" > <ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/guide_2"/> </RelativeLayout>
trhee.xml
<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=".MainActivity" > <ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/guide_3"/> <LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<!-- 进入主页面按钮 -->
<Button android:id="@+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开始"/>
</LinearLayout>
</RelativeLayout>
Guide acitvity:
import java.util.ArrayList;
import java.util.List; import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView; //引导页面
//1.实现引导页面三张引导图通过左右滑动屏幕可以实现切换
//2.在引导页面下面添加导航条,滑动过程中,让当前页面的导航条处于选中状态
//3.在引导页面的最后一个页面添加进入主页面按钮,点击按钮进入主页面
public class Guide extends Activity implements OnPageChangeListener { private List<View> views;
private ViewPagerAdapter vpa;
private ViewPager vp;
private ImageView[] ivs;
private int[] ids=new int[]{R.id.iv1,R.id.iv2,R.id.iv3}; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.guide);
initViews();
initIvs();
} private void initViews(){
//通过LayoutInflater 加载三个引导页面
LayoutInflater inflater=LayoutInflater.from(this);
views=new ArrayList<View>();
views.add(inflater.inflate(R.layout.one, null));
views.add(inflater.inflate(R.layout.two, null));
views.add(inflater.inflate(R.layout.three, null)); vpa=new ViewPagerAdapter(views, this);
vp=(ViewPager)findViewById(R.id.viewPager1);
vp.setAdapter(vpa);
//为ViewPager设置监听事件
vp.setOnPageChangeListener(this);
//点击第三个页面的开始按钮,进入主页面
Button btn=(Button) views.get(2).findViewById(R.id.btnStart);
btn.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
Intent i=new Intent(Guide.this,MainActivity.class);
startActivity(i);
finish();
}
});
}
// 加载导航条的ImageView
private void initIvs(){
ivs=new ImageView[views.size()];
for(int i=0;i<views.size();i++){
ivs[i]=(ImageView)findViewById(ids[i]);
}
} @Override
public void onPageScrollStateChanged(int arg0) {
} @Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
} // ViewPager监听事件,当ViewPager页面改变的时候,设置当前导航条的状态为选中状态
@Override
public void onPageSelected(int arg0) {
for(int i=0;i<ids.length;i++){
if(arg0==i){
ivs[i].setImageResource(R.drawable.login_point_selected);
}else{
ivs[i].setImageResource(R.drawable.login_point);
}
}
} }
ViewPagerAdapter 容器:
import java.util.List; import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
// 继承自PagerAdapter,并且实现添加引导页和移除引导页的方法
public class ViewPagerAdapter extends PagerAdapter{ private List<View> views;
private Context context; public ViewPagerAdapter(List<View> views,Context context){
this.views=views;
this.context=context;
} @Override
public Object instantiateItem(View container, int position) {
((ViewPager)container).addView(views.get(position));
return views.get(position);
} @Override
public void destroyItem(View container, int position, Object object) { ((ViewPager)container).removeView(views.get(position));
} @Override
public int getCount() {
return views.size();
} @Override
public boolean isViewFromObject(View arg0, Object arg1) {
return (arg0==arg1);
} }
最后设置AndroidManifest.xml:
<activity
android:name="com.example.lo12viewpager2.MainActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.example.lo12viewpager2.Guide"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.example.lo12viewpager2.Welcome"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
效果:
AndroidUI 引导页面的使用的更多相关文章
- swift3.0 创建一个app引导页面
swift毕竟不像是oc ,第三方的框架很多,更何况是3.0,自己动手写了个引导页面,看得上我代码的麻友可以拿去用 引导页面有三个部分构成,scrollview用语切换引导视图,pageControl ...
- android UI进阶之用ViewPager实现欢迎引导页面
ViewPager需要android-support-v4.jar这个包的支持,来自google提供的一个附加包.大家搜下即可. ViewPager主要用来组织一组数据,并且通过左右滑动的方式来展示. ...
- iOS 应用首次开启 出现引导页面
关于引导页面 ,可以是独立的一个视图控制器控制的滚动视图. 重点是处理 如何判断app是首次开启 而调用这个视图控制器得方法. 逻辑如下: -(BOOL)isFirstLoad { if(!标记第一次 ...
- 使用 StoryBoard 的时候加入用户引导页面
如果想让一个APP加上引导页面是一个非常完美的举动 但是,总会遇到一些问题 (不要忘记在APDelegate里面加上用户引导页面的头文件和程序启动时的第一个页面哦) 情况一:纯代码 判断是否是第一次启 ...
- Android开发必知--WebView加载html5实现炫酷引导页面
大多数人都知道,一个APP的引导页面还是挺重要的,不过要想通过原生的Android代码做出一个非常炫酷的引导页相对还是比较复杂的,正巧html5在制作炫酷动画网页方面比较给力,我们不妨先利用html5 ...
- android UI进阶之用ViewPager实现欢迎引导页面[转]
ViewPager需要android-support-v4.jar这个包的支持,来自google提供的一个附加包.大家搜下即可. ViewPager主要用来组织一组数据,并且通过左右滑动的方式来展示. ...
- App引导页面源代码的实现
一.页面效果图
- ViewPager实现启动引导页面(个人认为很详细)
效果如图: 启动页面是一张图片+延时效果,这里就不给出布局文件了. WelcomeActivity分析:在启动页面检测是否是第一次运行程序,如果是,则先跳转到引导界面的Activity——AndyVi ...
- Android欢迎页面以及引导页面
开发环境:Windows 10 x64,Android Studio 3.0 很多APP都会在启动主界面(MainActivity)之前显示一个短暂的欢迎页面,设置微博,知乎,百度之类APP还是在欢迎 ...
随机推荐
- Dynamics CRM 2013 初体验(3):新增加的功能
新系统除了修补系统历史漏洞外当然还会添加些比较有意思的新功能,至于这些新功能是否好用那就得看它是否能经过咱们这些使用者的考验了.Dynamics CRM 2013系统将不再支持Dynamics CRM ...
- thinkphp中的_get,_post,_request
ThinkPHP没有改变原生的PHP系统变量获取方式,所以依然可以通过$_GET. $_POST.$_SERVER.$_REQUEST 等方式 来获取系统变量,不过系统的Action类提供了对系统变量 ...
- Ruby小例子
1.ruby定义函数与执行函数案例 def fact(n) ) end end print fact() 结果: 24 2.一个小例子 words = [)] print "guess?\n ...
- JIRA官方:JIRA源代码集成
防火墙后的Git 使用Atlassian Stash创建和管理Git存储库,设置细粒度的权限并在代码上协作.这一切—安全.快速.可靠,更重要的是,可以部署在防火墙后面.JIRA问题关键字自动将JIRA ...
- myeclipse 2013 git
1. 2.添加site http://download.eclipse.org/egit/updates-2.3 3.安装 完成后,查看windows->preference的team下面有gi ...
- ARM上的linux如何实现无线网卡的冷插拔和热插拔
ARM上的linux如何实现无线网卡的冷插拔和热插拔 fulinux 凌云实验室 1. 冷插拔 如果在系统上电之前就将RT2070/RT3070芯片的无线网卡(以下简称wlan)插上,即冷插拔.我们通 ...
- OAuth2.0服务器端的实现
authorize 授权关系存储表字段 备注appid 应用IDuserid 用户IDaddtime 添加时间…… 其他表3 access_token 访问令牌存储表字段 备注access_token ...
- 告示:CSDN博客通道支持Windows Live Writer写blog离线好友
尊敬的各位CSDN用户: 您好! 为了更好的服务客户.CSDN已经支持Windows Live Writer离线写博客啦.Windows Live Writer于2014年5月29日正式上线啦!欢迎大 ...
- javascript常用的内置对象实用操作
1.indexOf() 方法 -----这个方法比较常用 返回某个指定的字符串值在字符串中首次出现的位置 使用格式:stringObject.indexOf(substring, startpos) ...
- 利用gridview实现计时消费,有点复杂,谁有好的方法可以讨论一下...
这是前段时间做项目遇到的一个问题,做出来的效果图如下, 由会员id查询出会员来,然后开始计费.然后点击结束消费,传到别的页面,主要就是结束时间和开始时间的一个时间差. 用到的数据表设计视图如下, 为了 ...