本文介绍Android侧边栏的自定义实现,要实现手指在手机上向左或向右移动时,能相应的移动左右两个视图。通过自定义来实现,不借助第三方插件。实现的思路很简单,通过判断手指滑动的距离和速度来决定是否要滚动显示菜单项.(左边图片)
先来看看效果:
目录:
一、实现思路
二、代码清单
三、效果与说明
本文源码下载
------------------------------------------分割线------------------------------------------
具体下载目录在 /2015年资料/2月/18日/Android侧边栏的自定义实现(附源码)/
------------------------------------------分割线------------------------------------------
下面,让我们开始吧:
一、实现思路
1.思路
菜单在左,内容在右,然后菜单显示时和手机右边框有一定的间隔,内容显示一小部分。内容全部显示时,菜单全部不可见。如下面两个图
显示内容
显示菜单
2.判断逻辑
这是判断手指按着屏幕和手指抬起时要不要显示还是隐藏菜单
二、代码清单
首先来看下布局:
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity" >
android:id="@+id/menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@drawable/pn" >
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background=