安卓_侧滑菜单
来源:互联网 发布:软考中级数据库工程师 编辑:程序博客网 时间:2024/06/05 07:35
这两天每天加班到十点钟,回来都累成狗了,也变懒了,好在深圳的温度还不算冷,昨晚的那个侧滑菜单讲解,由于没有给出案例,今天惦记了一整天,今晚就把简单的实现写出来,
不说什么了,上一章都讲完了。这里就只讲实现和细节优化有功能,今晚先把基本实现贴出来,周末来优化,麻蛋,下周就放假happy了,明天还要上班.好了,看效果图把
布局文件代码
<?xml version="1.0" encoding="utf-8"?><com.reeman.demo.DragViewGroup 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"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorAccent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="asdfjhbasdf" /> </LinearLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorPrimaryDark"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="asdfjhbasdf" /> </RelativeLayout></com.reeman.demo.DragViewGroup>
View代码
package com.reeman.demo;import android.content.Context;import android.support.v4.view.ViewCompat;import android.support.v4.widget.ViewDragHelper;import android.util.AttributeSet;import android.view.MotionEvent;import android.view.View;import android.widget.FrameLayout;/** * Created by Administrator on 2017/1/13. */public class DragViewGroup extends FrameLayout { ViewDragHelper mViewDragHelper; View mMenuView, mMainView; int mWidth; public DragViewGroup(Context context) { this(context, null); } public DragViewGroup(Context context, AttributeSet attrs) { this(context, attrs, 0); } public DragViewGroup(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); initView(); } @Override protected void onFinishInflate() { super.onFinishInflate(); mMenuView = getChildAt(0); mMainView = getChildAt(1); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mWidth = mMenuView.getMeasuredWidth(); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { return mViewDragHelper.shouldInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent event) { mViewDragHelper.processTouchEvent(event); return true; } private void initView() { mViewDragHelper = ViewDragHelper.create(this, callBack); } private ViewDragHelper.Callback callBack = new ViewDragHelper.Callback() { public boolean tryCaptureView(View child, int pointerId) { return mMainView == child; } //处理水平滑动的事件 @Override public int clampViewPositionHorizontal(View child, int left, int dx) { return left; } //处理垂直滑动的事件 @Override public int clampViewPositionVertical(View child, int top, int dy) { return 0; } //拖动结束后调用 @Override public void onViewReleased(View releasedChild, float xvel, float yvel) { super.onViewReleased(releasedChild, xvel, yvel); if (mMainView.getLeft() < 500) { //关闭菜单 mViewDragHelper.smoothSlideViewTo(mMainView, 0, 0); ViewCompat.postInvalidateOnAnimation(DragViewGroup.this); } else { //打开菜单 mViewDragHelper.smoothSlideViewTo(mMainView, 300, 0); ViewCompat.postInvalidateOnAnimation(DragViewGroup.this); } } }; @Override public void computeScroll() { if (mViewDragHelper.continueSettling(true)) { ViewCompat.postInvalidateOnAnimation(this); } }}由于没有处理左滑的事件,界面有些奇怪,代码里面注释讲解上一章有记录,代码比较简单,看看就能懂,
0 0
- 安卓_侧滑菜单
- 安卓简单的侧滑菜单
- 浅析安卓5.0 侧滑菜单
- 安卓实现自定义侧滑菜单
- 侧滑菜单--狸菇凉_
- 安卓_侧拉
- 安卓碎片fragment菜单侧滑slidingmenu
- 安卓实现QQ侧滑菜单效果
- 安卓Andriod使用入门(五)【分类侧滑菜单】
- 安卓SlideMenu 仿QQ 主页侧滑菜单
- 安卓动态菜单
- 安卓-菜单简述
- 安卓菜单
- 安卓_异常_
- 安卓开发_自定义控件_界面的简单侧滑
- 安卓_侧滑
- 安卓_动画
- 安卓_解析
- Boxes in a Line UVA - 12657
- Android Studio导入Eclipse工程的步骤
- Maven Profile 多环境构建
- 聊聊高并发系统之限流特技-2
- OpenCV学习笔记(01) :读取图片并显示
- 安卓_侧滑菜单
- C++的static_cast作用
- c——复合类型——数组
- Maven
- 2017.1.13【初中部 】普及组模拟赛C组 excel 电子表格 题解
- mysql sql语句大全
- 13.2 连接到世界银行
- 递归和动态规划专题(二)----剑指offer+左程云算法
- 汇编实验16 编写包含多个功能子程序的中断例程——浅谈直接地址表