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


最近Android项目中做到一个帮助的功能,具体就是点击帮助按钮后,出现仿新浪客户端的帮助功能的效果,是使用android的ViewPager来完成的,上网大概查了下相关的博客和资料,效果都不是太理想,估摸着这个又很常用,所以记录下来,希望能帮助到正在学习它的同学,也以免自己今后忘记了,算是一举两得吧。具体效果图如下:

图一

图二

  图三

  图四

首先我贴上这个项目的结构图:

图五

第一步,展示图一布局,编辑activity_main.xml,代码如下(jar包什么的,我就不多说了,工程图中libs有标出了,没有自己去下载个,不然我下面也有附件提供下载):

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  2.     xmlns:tools="http://schemas.android.com/tools" 
  3.     android:layout_width="match_parent" 
  4.     android:layout_height="match_parent"   
  5.     android:background="@drawable/tip2_2" 
  6.     > 
  7.  <LinearLayout 
  8.         android:layout_alignParentBottom="true" 
  9.         android:layout_width="fill_parent" 
  10.         android:layout_height="wrap_content" 
  11.         android:layout_gravity="bottom" 
  12.         android:clickable="false" 
  13.         android:focusable="false" 
  14.       > 
  15.          <Button   
  16.             android:id="@+id/btn_my_menu"   
  17.             android:layout_width="fill_parent"   
  18.             android:layout_height="wrap_content"   
  19.             android:gravity="center"   
  20.             android:layout_weight="1"   
  21.             android:paddingTop="12dp"   
  22.             android:paddingBottom="12dp"   
  23.             android:textSize="15sp"   
  24.             android:textColor="@android:color/white" 
  25.             android:background="@drawable/my3_menu_button" 
  26.             android:textStyle="bold"   
  27.             android:focusable="true"/>   
  28.          
  29.          
  30.         <Button 
  31.             android:id="@+id/btn_help" 
  32.             android:layout_width="fill_parent" 
  33.             android:layout_height="wrap_content" 
  34.             android:layout_weight="1" 
  35.             android:background="@drawable/help3_menu_button" 
  36.             android:gravity="center" 
  37.             android:paddingBottom="12dp" 
  38.             android:paddingTop="12dp" 
  39.             android:textColor="@android:color/white" 
  40.             android:textSize="15sp" 
  41.             android:textStyle="bold"   
  42.             android:focusable="true"/> 
  43.    
  44.              
  45.            <Button   
  46.             android:id="@+id/btn_share"   
  47.             android:layout_width="fill_parent"   
  48.             android:layout_height="wrap_content"   
  49.             android:background="@drawable/share3_menu_button" 
  50.             android:gravity="center"   
  51.             android:paddingTop="12dp"   
  52.             android:paddingBottom="12dp"   
  53.             android:layout_weight="1"   
  54.             android:textSize="15sp"   
  55.             android:textColor="@android:color/white" 
  56.             android:textStyle="bold" 
  57.             android:focusable="true"   
  58.            />   
  59.     </LinearLayout> 
  60.  
  61. </RelativeLayout> 
  • 1
  • 2
  • 3
  • 4
  • 下一页

相关内容