package com.example.fragmenttest.slidingmenu;
import java.util.ArrayList;
import java.util.List;
import com.example.fragmenttest.slidingmenu.SlidingMenu.OnClosedListener;
import com.example.fragmenttest.slidingmenu.SlidingMenu.OnOpenedListener;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Build;
import android.support.v4.view.KeyEventCompat;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.VelocityTrackerCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewConfigurationCompat;
import android.util.AttributeSet;
import android.util.FloatMath;
import android.util.Log;
import android.view.FocusFinder;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.SoundEffectConstants;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.animation.Interpolator;
import android.widget.Scroller;
/**
* 定时view组
* @author wdply
*
*/
//import com.slidingmenu.lib.SlidingMenu.OnCloseListener;
//import com.slidingmenu.lib.SlidingMenu.OnOpenListener;
public class CustomViewAbove extends ViewGroup {
private static final String TAG = "CustomViewAbove";
private static final boolean DEBUG = true;
private static final boolean USE_CACHE = false;
private static final int MAX_SETTLE_DURATION = 600; // ms
private static final int MIN_DISTANCE_FOR_FLING = 25; // dips
private static final Interpolator sInterpolator = new Interpolator() {
public float getInterpolation(float t) {
t -= 1.0f;
return t * t * t * t * t + 1.0f;
}
};
private View mContent;
private int mCurItem;
private Scroller mScroller;
private boolean mScrollingCacheEnabled;
private boolean mScrolling;
private boolean mIsBeingDragged;
private boolean mIsUnableToDrag;
private int mTouchSlop;
private float mInitialMotionX;
/**
* Position of the last motion event.
*/
private float mLastMotionX;
private float mLastMotionY;
/**
* ID of the active pointer. This is used to retain consistency during
* drags/flings if multiple pointers are used.
*/
protected int mActivePointerId = INVALID_POINTER;
/**
* Sentinel value for no current active pointer.
* Used by {@link #mActivePointerId}.
*/
private static final int INVALID_POINTER = -1;
/**
* Determines speed during touch scrolling
*/
protected VelocityTracker mVelocityTracker;
private int mMinimumVelocity;
protected int mMaximumVelocity;
private int mFlingDistance;
private CustomViewBehind mViewBehind;
// private int mMode;
private boolean mEnabled = true;
private OnPageChangeListener mOnPageChangeListener;
private OnPageChangeListener mInternalPageChangeListener;
// private OnCloseListener mCloseListener;
// private OnOpenListener mOpenListener;
private OnClosedListener mClosedListener;
private OnOpenedListener mOpenedListener;
private List<View> mIgnoredViews = new ArrayList<View>();
// private int mScrollState = SCROLL_STATE_IDLE;
/**
* Callback interface for responding to changing state of the selected page.
*/
public interface OnPageChangeListener {
/**
* This method will be invoked when the current page is scrolled, either as part
* of a programmatically initiated smooth scroll or a user initiated touch scroll.
*
* @param position Position index of the first page currently being displayed.
* Page position+1 will be visible if positionOffset is nonzero.
* @param positionOffset Value from [0, 1) indicating the offset from the page at position.
* @param positionOffsetPixels Value in pixels indicating the offset from position.
*/
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels);
/**
* This method will be invoked when a new page becomes selected. Animation is not
* necessarily complete.
*
* @param position Position index of the new selected page.
*/
public void onPageSelected(int position);
}
/**
* Simple implementation of the {@link OnPageChangeListener} interface with stub
* implementations of each method. Extend this if you do not intend to override
* every method of {@link OnPageChangeListener}.
*/
public static class SimpleOnPageChangeListener implements OnPageChangeListener {
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
// This space for rent
}
public void onPageSelected(int position) {
// This space for rent
}
public void onPageScrollStateChanged(int state) {
// This space for rent
}
}
public CustomViewAbove(Context context) {
this(context, null);
}
public CustomViewAbove(Context context, AttributeSet attrs) {
super(context, attrs);
initCustomViewAbove();
}
void initCustomViewAbove() {
// setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
setDescendantFocusability(FOCUS_BEFORE_DESCENDANTS);
setClickable(true);
setFocusable(true);
setWillNotDraw(false);
final Context context = getContext();
mScroller = new Scroller(context, sInterpolator);
final ViewConfiguration configuration = ViewConfiguration.get(context);
mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
setInternalPageChangeListener(new SimpleOnPageChangeListener() {
public void onPageSelected(int position) {
if (mViewBehind != null) {
switch (position) {
case 0:
case 2:
mViewBehind.setChildrenEnabled(true);
break;
case 1:
mViewBehind.setChildrenEnabled(false);
break;
}
}
}
});
final float density = context.getResources().getDisplayMetrics().density;
mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
}
/**
* Set the currently selected page. If the CustomViewPager has already been through its first
* layout there will be a smooth animated transition between the current item and the
* specified item.
*
* @param item Item index to select
*/
public void setCurrentItem(int item) {
setCurrentItemInternal(item, true, false);
}
/**
* Set the currently selected page.
*
* @param item Item index to select设置当前选择的页面
* @param smoothScroll True to smoothly scroll to the new item, false to transition immediately
*/
public void setCurrentItem(int item, boolean smoothScroll) {
setCurrentItemInternal(item, smoothScroll, false);
}
public int getCurrentItem() {
return mCurItem;
}
void setCurrentItemInternal(int item, boolean smoothScroll, boolean always) {
setCurrentItemInternal(item, smoothScroll, always, 0);
}
/**
* 设置菜单宽度
* @param item
* @param smoothScroll
* @param always
* @param velocity
*/
void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int velocity) {
if (!always && mCurItem == item) {
setScrollingCacheEnabled(false);
// System.out.println("返回");
return;
}
// System.out.println("继续");
item = mViewBehind.getMenuPage(item);
final boolean dispatchSelected = mCurItem != item;
mCurItem = item;
final int destX = getDestScrollX(mCurItem);
if (dispatchSelected && mOnPageChangeListener != null) {
// System.out.println("第一个");
mOnPageChangeListener.onPageSelected(item);
}
if (dispatchSelected && mInternalPageChangeListener != null) {
// System.out.println("第二个");
mInternalPageChangeListener.onPageSelected(item);
}
// if (smoothScroll) {
// // System.out.println("wei真"+destX);
// if (item==2) {
// System.out.println("进入2");
// smoothScrollTo1(destX, 0, velocity);
// }else {
// System.out.println("进入1");
// smoothScrollTo(destX, 0, velocity);
// }
//
// } else {
// completeScroll();
// scrollTo(destX, 0);
// }
if (smoothScroll) {
System.out.println(
没有合适的资源?快使用搜索试试~ 我知道了~
slidingMenu修改左右宽度
共8个文件
java:8个
5星 · 超过95%的资源 需积分: 16 20 下载量 195 浏览量
2014-03-10
20:51:09
上传
评论
收藏 28KB RAR 举报
温馨提示
slidingMenu 左右滑动,修改原始样子,自定义左右菜单的宽度不同
资源推荐
资源详情
资源评论
收起资源包目录
slidingMenu修改左右宽度.rar (8个子文件)
slidingMenu修改左右宽度
slidingmenu
CustomViewAbove.java 34KB
CustomViewBehind.java 13KB
SlidingActivityHelper.java 6KB
MainActivity.java 8KB
SlidingMenu.java 32KB
BaseSlidingFragmentActivity.java 4KB
SlidingActivityBase.java 2KB
BounceScrollView.java 4KB
共 8 条
- 1
资源评论
- gtchjc2014-08-07如果设置右边菜单宽度为0的话 那么如何关闭右侧打开的slidingmenu,请指点 hanjchao@foxmail.com
- 小时候可坏了丷2014-05-29不错,有帮助,感谢
- 星宇凡尘2014-07-30开始也在研究怎么设置左右不同宽度,想法和楼主差不多,但不确定,找到楼主分享的以后,坚定了自己的想法,谢谢
- afeizhuanyong2014-04-26不错,有帮助,感谢
- a5120162014-03-20只有几个java文件,不知道什么意思,替换原版库里的对应文件?但是文件名不全一样。。反正觉得另一个http://download.csdn.net/detail/qq122810986/6754961才比较实用。不过下面这个库有错误,需要先修改。
plywd
- 粉丝: 10
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功