Android中使用ViewPager实现图片左右拖动
Android中使用ViewPager实现图片左右拖动
最近Android项目中做到一个帮助的功能,具体就是点击帮助按钮后,出现仿新浪客户端的帮助功能的效果,是使用android的ViewPager来完成的,上网大概查了下相关的博客和资料,效果都不是太理想,估摸着这个又很常用,所以记录下来,希望能帮助到正在学习它的同学,也以免自己今后忘记了,算是一举两得吧。具体效果图如下:
图一
图二
图三
图四
首先我贴上这个项目的结构图:
图五
第一步,展示图一布局,编辑activity_main.xml,代码如下(jar包什么的,我就不多说了,工程图中libs有标出了,没有自己去下载个,不然我下面也有附件提供下载):
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@drawable/tip2_2"
- >
- <LinearLayout
- android:layout_alignParentBottom="true"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="bottom"
- android:clickable="false"
- android:focusable="false"
- >
- <Button
- android:id="@+id/btn_my_menu"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:layout_weight="1"
- android:paddingTop="12dp"
- android:paddingBottom="12dp"
- android:textSize="15sp"
- android:textColor="@android:color/white"
- android:background="@drawable/my3_menu_button"
- android:textStyle="bold"
- android:focusable="true"/>
- <Button
- android:id="@+id/btn_help"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="@drawable/help3_menu_button"
- android:gravity="center"
- android:paddingBottom="12dp"
- android:paddingTop="12dp"
- android:textColor="@android:color/white"
- android:textSize="15sp"
- android:textStyle="bold"
- android:focusable="true"/>
- <Button
- android:id="@+id/btn_share"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:background="@drawable/share3_menu_button"
- android:gravity="center"
- android:paddingTop="12dp"
- android:paddingBottom="12dp"
- android:layout_weight="1"
- android:textSize="15sp"
- android:textColor="@android:color/white"
- android:textStyle="bold"
- android:focusable="true"
- />
- </LinearLayout>
- </RelativeLayout>
|
评论暂时关闭