android导航页(欢迎页实现十分简单)

  • 首先要弄明白原理,大致了解一下该流程


    1、创建一个类继承自SimplePagerFragment,实现对导航页面的页面循环的设置、背景颜色的设置以及页面监听事件的设置
    2、创建类定义每一个的页面(有多少页就创建多少个页面,当然布局文件是肯定需要的不再赘叙)
    3、在Activity中启动
  • 创建创建一个类继承自SimplePagerFragment代码如下:
        
        
    1. package com.cleveroad.slidingtutorial.sample;
    2. import android.graphics.Color;
    3. import android.support.annotation.ColorInt;
    4. import android.support.v4.content.ContextCompat;
    5. import android.view.View;
    6. import android.widget.Toast;
    7. import com.cleveroad.slidingtutorial.PageFragment;
    8. import com.cleveroad.slidingtutorial.SimplePagerFragment;
    9. //此处继承自SimplePagerFragment查看库文件代码发现SimplePagerFragment继承自CustomPresentationPagerFragment
    10. public class CustomPresentationPagerFragment extends SimplePagerFragment {
    11. //获取页面个数
    12. @Override
    13. protected int getPagesCount() {
    14. return 6;
    15. }
    16. //注意此处是背景上所添加的图案的循环出现的次数,运行安装后可以发现第一个页面(position=0)的图案和第四个(position=3)是相同的就是在此处设置的
    17. @Override
    18. protected PageFragment getPage(int position) {
    19. position %= 3;
    20. if (position == 0)
    21. return new FirstCustomPageFragment();
    22. if (position == 1)
    23. return new SecondCustomPageFragment();
    24. if (position == 2)
    25. return new ThirdCustomPageFragment();
    26. throw new IllegalArgumentException("Unknown position: " + position);
    27. }
    28. //设置背景颜色,现在越来越多的软件背景都是以颜色代替呈现一种扁平化的感觉,也可以自定义图片
    29. @ColorInt
    30. @Override
    31. protected int getPageColor(int position) {
    32. if (position == 0)
    33. return ContextCompat.getColor(getContext(), android.R.color.holo_orange_dark);
    34. if (position == 1)
    35. return ContextCompat.getColor(getContext(), android.R.color.holo_green_dark);
    36. if (position == 2)
    37. return ContextCompat.getColor(getContext(), android.R.color.holo_blue_dark);
    38. if (position == 3)
    39. return ContextCompat.getColor(getContext(), android.R.color.holo_red_dark);
    40. if (position == 4)
    41. return ContextCompat.getColor(getContext(), android.R.color.holo_purple);
    42. if (position == 5)
    43. return ContextCompat.getColor(getContext(), android.R.color.darker_gray);
    44. return Color.TRANSPARENT;
    45. }
    46. //是否循环滑动(true一直循环滑动不进入程序,false相反)
    47. @Override
    48. protected boolean isInfiniteScrollEnabled() {
    49. return true;
    50. }
    51. //监听事件(页面上左下角Skip的点击事件---布局代码都在库文件中不可修改但是如果需要自己定义点击图标以及事件可以继承其抽象类的抽象方法去实现
    52. @Override
    53. protected boolean onSkipButtonClicked(View skipButton) {
    54. Toast.makeText(getContext(), "Skip button clicked", Toast.LENGTH_SHORT).show();
    55. return true;
    56. }
    57. }
  • 设置单个页面(有多少个就设置多少个是不是很简单!):
        
        
    1. public class FirstCustomPageFragment extends PageFragment {
    2. //获取布局文件的ID
    3. @Override
    4. protected int getLayoutResId() {
    5. return R.layout.fragment_page_first;
    6. }
    7. /*为界面上的各个元素设置移动因素,包括方向和系数。一个TransformItem就是一个界面元素,其中它的第一个参数是界面元素对应的id,第二个参数是是否反向,true表示要,false表示不,第三个参数是移动系数。系数越大移动越慢,为一个界面上的不同元素设置不同的方向和系数,就能形成视差效果。**/
    8. @Override
    9. protected TransformItem[] provideTransformItems() {
    10. return new TransformItem[]{
    11. new TransformItem(R.id.ivFirstImage, true, 20),
    12. new TransformItem(R.id.ivSecondImage, false, 6),
    13. new TransformItem(R.id.ivThirdImage, true, 8),
    14. new TransformItem(R.id.ivFourthImage, false, 10),
    15. new TransformItem(R.id.ivFifthImage, false, 3),
    16. new TransformItem(R.id.ivSixthImage, false, 9),
    17. new TransformItem(R.id.ivSeventhImage, false, 14),
    18. new TransformItem(R.id.ivEighthImage, false, 7)
    19. };
    20. }
    21. }
  • 相对应的布局文件(此处使用的是百分比布局,如果要使用该形式的布局是需要导入百分比布局的库文件的否则编译不通过:'com.android.support:percent:22.2.0'):
        
        
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <android.support.percent.PercentRelativeLayout
    3. android:id="@+id/rootFirstPage"
    4. xmlns:android="http://schemas.android.com/apk/res/android"
    5. xmlns:app="http://schemas.android.com/apk/res-auto"
    6. xmlns:tools="http://schemas.android.com/tools"
    7. android:layout_width="match_parent"
    8. android:layout_height="match_parent"
    9. tools:ignore="ContentDescription"
    10. tools:background="@android:color/holo_orange_dark">
    11. <ImageView
    12. android:id="@+id/ivFirstImage"
    13. android:layout_width="wrap_content"
    14. android:layout_height="wrap_content"
    15. android:layout_centerInParent="true"
    16. android:src="@mipmap/s_0_1"
    17. app:layout_heightPercent="35%"
    18. app:layout_widthPercent="50%"/>
    19. <ImageView
    20. android:id="@+id/ivSecondImage"
    21. android:layout_width="wrap_content"
    22. android:layout_height="wrap_content"
    23. android:layout_alignParentEnd="true"
    24. android:layout_alignParentRight="true"
    25. android:src="@mipmap/s_0_2"
    26. app:layout_heightPercent="10%"
    27. app:layout_marginRightPercent="12%"
    28. app:layout_marginTopPercent="27%"
    29. app:layout_widthPercent="12%"/>
    30. <ImageView
    31. android:id="@+id/ivThirdImage"
    32. android:layout_width="wrap_content"
    33. android:layout_height="wrap_content"
    34. android:src="@mipmap/s_0_3"
    35. app:layout_heightPercent="25%"
    36. app:layout_marginLeftPercent="14%"
    37. app:layout_marginTopPercent="49%"
    38. app:layout_widthPercent="30%"/>
    39. <ImageView
    40. android:id="@+id/ivFourthImage"
    41. android:layout_width="wrap_content"
    42. android:layout_height="wrap_content"
    43. android:src="@mipmap/s_0_4"
    44. app:layout_heightPercent="15%"
    45. app:layout_marginLeftPercent="14%"
    46. app:layout_marginTopPercent="39%"
    47. app:layout_widthPercent="20%"/>
    48. <ImageView
    49. android:id="@+id/ivFifthImage"
    50. android:layout_width="wrap_content"
    51. android:layout_height="wrap_content"
    52. android:layout_centerHorizontal="true"
    53. android:src="@mipmap/s_0_5"
    54. app:layout_heightPercent="15%"
    55. app:layout_marginTopPercent="22%"
    56. app:layout_widthPercent="45%"/>
    57. <ImageView
    58. android:id="@+id/ivSixthImage"
    59. android:layout_width="wrap_content"
    60. android:layout_height="wrap_content"
    61. android:src="@mipmap/s_0_6"
    62. app:layout_heightPercent="6%"
    63. app:layout_marginLeftPercent="4%"
    64. app:layout_marginTopPercent="26%"
    65. app:layout_widthPercent="6%"/>
    66. <ImageView
    67. android:id="@+id/ivSeventhImage"
    68. android:layout_width="wrap_content"
    69. android:layout_height="wrap_content"
    70. android:src="@mipmap/s_0_7"
    71. app:layout_heightPercent="8%"
    72. app:layout_marginLeftPercent="14%"
    73. app:layout_marginTopPercent="25%"
    74. app:layout_widthPercent="9%"/>
    75. <ImageView
    76. android:id="@+id/ivEighthImage"
    77. android:layout_width="wrap_content"
    78. android:layout_height="wrap_content"
    79. android:src="@mipmap/s_0_8"
    80. app:layout_heightPercent="6%"
    81. app:layout_marginLeftPercent="77%"
    82. app:layout_marginTopPercent="38%"
    83. app:layout_widthPercent="8%"/>
    84. <TextView
    85. android:layout_width="wrap_content"
    86. android:layout_height="wrap_content"
    87. android:layout_alignParentBottom="true"
    88. android:layout_centerHorizontal="true"
    89. android:gravity="center"
    90. android:text="@string/text_web_ceo"
    91. android:textColor="@android:color/white"
    92. android:textSize="@dimen/text_size_large"
    93. app:layout_heightPercent="15%"
    94. app:layout_marginBottomPercent="11%"
    95. app:layout_widthPercent="45%"/>
    96. </android.support.percent.PercentRelativeLayout>
    此时导航页面是无限循环的如果需要判断用户是否是第一次启动该软件用savedInstanceState判断一下,MainActivity 中代码较少也简单主要是用了一个replaceTutorialFragment()方法。
  • 具体代码下载地址:https://github.com/Cleveroad/SlidingTutorial-Android.git
  • 如果下载总是中间停止可以用SVN下载无需用户名及密码
  • 如转载请标明转载地址,写的不好尽情谅解!
  • 如有问题可以加我qq:2915859312联系!
  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
====================================================================== V1.13 (2009年12月14日修复列表) .# 对在线升级功能进行了改进,提高兼容性和稳定性。 .# 对程序进行优化,后台运行效率明显加快; .# 修改地方服务子分类不可修改Bug; .# 修复修改网址信息后自动跳转会出现2000秒倒数的Bug; .# 修复天气自动判断显示为“东莞”的Bug; .# 修复内不能正常显示用户自定义背景的Bug; .# 修复名站切换栏“我的收藏”网址IE浏览器下不在新窗口打开的Bug; .# 修复部分环境下后台左侧菜单不显示的Bug; .# 改进批量导入网址功能; .# 修正清空关键词分类后静态生成出错的Bug; .# 修正生成分类为空分类时出错的Bug; V1.13 (2009年11月30日发布) .#增加在线升级功能,自动判断升级,方便及时修复bug和后续版本升级; .#对程序进行优化,增强程序兼容性,运行效率更高; .#增加批量导入网址的功能,可在短时间内导入更多数据; .#重写模版,简化模版标签,使用户制作模版更简单; .#增加模版选择器模块,规范模版制作,方便站长用户使用多种模版; .#优化首搜索框调用和配置,使用户可以快速填入搜索联盟代码; .#修改广告调用模式,用户可直接写入代码,增强可操控性; .#新增站长需要的闹钟、滚动新闻、天气预报定制等功能; .#调整和优化系统菜单的功能及相关说明,使站长更方便使用; .#优化首模版设计,与官方同步,经测试首搜索框设计可增加搜索量; .#改进网站管理,分类管理的用户体验,操作更方便快捷; .#实现酷站导航分类独立化,改内关联为独立设置,增强了可操作性; .#实现“行业网站”模块化,可独立定制行业网站; .#实现“地方服务”模块独立化,分列各省地方服务,丰富网站内容; .#实现分类导航和酷站导航自适应拉伸,减轻站长调试负担; .#修复V1.12版本站长们提交的各种BUG或者修改建议,不一一列出; V1.12 0921升级补丁包 (2009年9月22日发布) *修复站点修复功能SMTP邮箱个别情况下开启失败的问题 *修复天气预报接口失效的问题 *对列车时刻查询插件性能优化,提高了查询速度 V1.12 0824升级补丁包 (2009年8月24日发布) *增加“天气详情”关联id的功能 *修复内因为关键词词语联想不能使用的问题 *修复使用cnzz站长统计代码首脚本错误的问题 *解决个别linux环境下,网址导航首无法生成的问题 *修复删除所有数据后“查看所有分类”不能显示的问题 V1.12 升级补丁包 (2009年7月26日发布) *优化静态生成功能,提高生成速度,解决php5环境下生成白屏的问题 *修改了服务器根目录不可写导致无法生成首的问题 *修复分类生成错误及分类多级管理错误的问题 *修复后台点酷站管理排序及列表宽度不能自适应的问题 *修复内title-站名合理位置 *修复顶部广告位图片高度和宽度的错误 *增加首、内、专题面统计代码,修复统计代码引起的脚本错误 *修复"网址列表"删除选项打勾时出现的“input”未定义的错误 *修复网站提交面头部调用错误的问题 *修复后台安全日志显示问题 V1.12 (2009年7月23日发布) * 以最新架构对程序进行重写,并优化了后台管理,增强了用户体验和交互性; * 升级数据统筹管理中数据库备份、恢复等功能,V1.10及V1.11数据可导入升级; * 提供“红河MySITES网址导航”数据库转换插件,以便让更多人使用114啦建站系统; * 升级静态面生成系统,可设置即时更新、自定义分类更新、更新全部分类三种选择; * 修复了安装时系统管理员账号不可自定义的功能; * 增加静态可在独立文件夹存放功能,如/html/youxi/index. htm; * 增加子分类面KeyWords和Description自定义修改功能; * 增加模板后台管理功能,并对主要的模板和标签都进行注解说明; * 升级顶部广告位管理,完全支持html,方便联盟广告添加; * 调整“网站收录”的功能,对一般站点不需要的提交选项进行简化; * 优化回收站的管理和操作流程,使恢复和删除站点更方便; * 优化站点统计引擎和缓存引擎,使系统在保证灵活性的同时也有更好的性能 * 优化网站管理细节,网站添加时后台同分类里如有相同网址,将有友好的错误提示; * 增加自定义网址收藏夹功能,用户可自行收藏全站网址到首,并可增删; * 增加一键清空原有114啦数据功能,方便站长做其它行业网址导航的需要; * 增加首底部专题管理功能,如“地方服务”,“网络游戏”,后台可修改,增删,排序等 * 增加各级子分类批量删除功能; * 增加名站导航切换栏,可以在后台修改调用网址,如“常用软件”,“热门游戏”之类; * 增加天气预报的定制功能,并移至天气处可展开未来三天的天气预报; * 增加程序升级提醒,方便站长获得官方升级信息 * 增加宽屏版及其他个性设置,如字体颜色、面背景、酷站对齐方式等设置; V1.11 (2009年6月30日发布) * 实现一键傻瓜式安装,无需手工导入数据库,轻松建站 * 整理了模版文件,使模版目录更清晰,制作风格更方便 * 修复了114啦数据库导入错误的问题 * 修复了统计代码不生效的问题 * 修复了生成静态乱码的问题 * 修复了首468x60 Banner广告设置不可用html代码的问题 * 解决了浏览记录个别情况下,使用不正常的问题 * 解决了“用户反馈”个别情况下不能使用的问题 V1.10 (2009年5月26日发布) * 采用Php+Mysql架构,搭建简易,程序运行稳定安全 * 集成114啦网址导航最新数据库,收录站点质量高 * 全站可见链接99%后台控制,站长可随心所欲定制 * 全站采用XHTML+CSS设计,符合W3C标准 * 一键全站html静态生成,可完全脱离数据库运行 * 功能强大的多用户权限管理,可委任多个权限组进行站点维护 * 分类清晰人性化,可自定义分类链接、可外链,更符合seo标准 * 全站链接可设置上线时间、过期时间、颜色定制、留空、网站备注等,方便广告需要 * 提供多种风格的皮肤、天气预报、日历等个性化功能 * 集成115聚合搜索、百度、Google等引擎入口,全方位搜索体验 * 提供站内网址搜索、网站浏览记录等功能 * 系统安全设置:安全验证、系统负载控制、CC防护设置、IP禁止……将风险防患于未然 * 整合网站收录申请查询、用户反馈等程序,便于了解网友需求,有助于改善用户体验 * 完善的数据库管理,可进行在线数据库备份、恢复、优化及修复 * 全面的日志管理:后台管理安全日志、MYSQL、PHP错误日志,便于程序监控和操作记录

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值