使用横向滚动栏HorizontalScrollView。利用加载一个透明的View占位置,然后使用scrollView.smoothScrollTo(left, 0);来滚动,监听手势动作。
获取水平滚动栏直接子View
LinearLayout parent=(LinearLayout) getChildAt(0); parent.addView(children[0], 410, 880); parent.addView(children[1], 536, 880);
一、MainActivity布局文件
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="2px" android:background="#00ffffff" android:padding="0px" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <RelativeLayout android:id="@+id/menu" android:layout_width="fill_parent" android:background="@drawable/desktop_list_item" android:layout_height="wrap_content" > <ImageView android:id="@+id/head" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="fitStart" android:src="@drawable/acount_head_photo" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignBottom="@+id/head" android:layout_marginLeft="10dip" android:layout_toRightOf="@+id/head" android:text="沈阳师范大学" android:textColor="@color/white" android:textSize="17dip" /> </RelativeLayout> <ListView android:id="@+id/HomeListView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:cacheColorHint="@android:color/transparent" android:divider="#000" /> </LinearLayout> <grimbo.android.demo.slidingmenu.MyHorizontalScrollView android:id="@+id/myScrollView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="0px" android:background="#00ffffff" android:fadingEdge="none" android:fadingEdgeLength="0px" android:padding="0px" > <LinearLayout android:id="@+id/top" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="0px" android:background="#00ffffff" android:orientation="horizontal" android:padding="0px" > </LinearLayout> </grimbo.android.demo.slidingmenu.MyHorizontalScrollView> </FrameLayout>
二、监听手势
public class MyGestureDetector extends SimpleOnGestureListener { //滑动 @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { float touchLength = Math.abs(e1.getY() - e2.getY()); System.out.println("touchLength="+touchLength); if (touchLength > SWIPE_MAX_OFF_PATH) return false; // 从右向左滑动 if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { System.out.println("SSSSSSSSSSSleftS"); int menuWidth = menu.getMeasuredWidth(); menu.setVisibility(View.VISIBLE); int left = menuWidth; scrollView.smoothScrollTo(left, 0); } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { int left = 0; scrollView.smoothScrollTo(left, 0); System.out.println("SSSSSSSSSSSleftS"+left); } } catch (Exception e) { Log.e("detector", "excetpion:" + e.getMessage()); } return false; } } @Override public boolean onTouchEvent(MotionEvent event) { if (gestureDetector.onTouchEvent(event)) return true; else return false; }
三、侧边栏布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/app" android:layout_width="1dp" android:layout_height="1dp" android:orientation="vertical" android:background="#ffffffff" android:padding="2px" android:layout_margin="2px"> <LinearLayout android:id="@+id/tabBar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:id="@+id/BtnSlide" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="0px" android:layout_margin="0px" android:src="@drawable/ic_launcher" /> <TextView android:text="<- Press icon" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> <ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ff00ff00" android:cacheColorHint="#ff00ff00"> </ListView> </LinearLayout>
相关推荐
android通过手势滑动实现侧边栏效果的Demo
本框架是类似于QQ、微信等的侧边栏效果框架,作者加入了绚丽的动画效果,更加吸引用户,而且本框架完全基于接口开发,充分考虑同学们在使用过程中的扩展和自定义!相当的绚丽,相当的人性化,值得集成!
类似与facebook的侧边栏效果, 可以展示左侧的内容、右侧的内容
DrawLayout侧边栏效果实现的代码
Android IOS风格侧边栏效果,ReisdeMenu 创意灵感来自于Dribbble(Dribbble是一个面向创作家、艺术工作者、设计师等创意类作品的人群,提供作品在线服务,供网友在线查看已经完成的作品,或者正在创作的作品.). ...
该侧边栏效果使用了activity嵌套fragment,其继承了SlidingFragmentActivity来实现的,侧边栏效果非常完美。
QQ的侧边栏效果 以及一些常用的侧边效果大全。非常非常全 不下你后悔
JS实现页面侧边栏效果探究 目录 发现:display动画的应用实现:如何实现文首展示的效果 发现:display动画的应用 实现:如何实现文首展示的效果 其实效果大概是这样的: 而标题,也许是我当时看到这种效果时...
模仿qq5.0的侧边栏效果,主要是增加了动画属性。
Android中的material-navigation-drawer 5.0侧边栏效果.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
用axure实现侧边栏展开效果,逼真的可以试试
SideNavigation 全屏适配 --- 采Swift开发史上最简洁的iOS侧边栏 效果
一次手势完成滑出侧边栏与选择菜单。欢迎下载 demo 体验。 效果 使用方法 添加依赖 compile 'com.github.mzule.fantasyslide:library:1.0.5' 调用 调用方法基本与 DrawerLayout 一致. 本项目支持左右 (start left ...
人人网提供侧边栏显示的样例程序,通俗易懂,对于初学者是个很好的参考程序
iOS 侧边栏效果.zip,lmsidebarcontroller是一个简单的边栏控制器,灵感来自tappy和simon hoang。
实例代码 博文链接:https://793101503-qq-com.iteye.com/blog/1545327
在开发Jquery Mobile的时候,我们往往需要侧边栏来导航我们所需的页面。自己整合了一些资源来实现我的目的
LMSideBarController是一个简单的iOS 侧边栏效果
基本上实现侧边栏滑动的效果,可以参考自己修改
这是一个很简单的示例,刚开始学习IOS不久,突然需要一个这种功能,看了网上的,都太过强大,本身看不太明白,也不太会维护,最后就自己简单处理了下手势,弄出了这个,发布上来供我们新手一起探讨。