手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Android中使用ViewPager实现图片左右拖动

[日期:2012-10-17] 来源:Linux社区  作者:johnjobs [字体:大 中 小]

第二步,新建图五中的help.xml布局文件,代码如下:

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <FrameLayout xmlns:Android="http://schemas.android.com/apk/res/android" 
  3.     android:layout_width="fill_parent" 
  4.     android:layout_height="fill_parent" 
  5.     android:orientation="vertical" > 
  6.  
  7.     <android.support.v4.view.ViewPager 
  8.         android:id="@+id/guidePages" 
  9.         android:layout_width="fill_parent" 
  10.         android:layout_height="wrap_content"/> 
  11.          
  12.     <RelativeLayout   
  13.         android:layout_width="fill_parent"   
  14.         android:layout_height="wrap_content"   
  15.         android:orientation="vertical" > 
  16.     <LinearLayout   
  17.         android:id="@+id/viewGroup"   
  18.         android:layout_width="fill_parent"   
  19.         android:layout_height="wrap_content"   
  20.         android:layout_alignParentBottom="true"   
  21.         android:layout_marginBottom="30dp"   
  22.         android:gravity="center_horizontal"   
  23.         android:orientation="horizontal" >   
  24.     </LinearLayout>   
  25.     </RelativeLayout> 
  26.  
  27. </FrameLayout> 

第三步,新建图五中的item01-item06.xml,因为它们是用来放置你左右滑动的图片的,如效果图我们可以看到,我的这个滑动,是支持六张图片的左右滑动的,所以这边儿我新建了item01-item06.xml,因为每个item.xml布局除了图片不一样,其他都一样,所以这里我就偷下懒,放item01.xml的代码,其余的几个xml大家自己复制item01后,改变下图片就行了。

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  3.     android:layout_width="fill_parent" 
  4.     android:layout_height="fill_parent" 
  5.     android:orientation="vertical" > 
  6.      
  7.     <ImageView   
  8.         android:layout_width="fill_parent"   
  9.         android:layout_height="fill_parent"   
  10.         android:background="@drawable/feature_guide_1" >   
  11.     </ImageView> 
  12.      
  13. </LinearLayout> 
linux
相关资讯       Android开发基础教程  ViewPager 
本文评论   查看全部评论 (1)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 1 楼
* za14356722会员 发表于 2014/2/26 14:30:00
R.drawable.page_indicator_focused
R.drawable.page_indicator
好像没给出来,哥们怎么写的?