先看看效果:
这是我阅读器上排行榜的筛选效果:
给个链接:http://www.eoemarket.com/show/index/?appId=97578
下面来介绍这个效果的实现方法:
1。首先,我自定义了一个SlideLayout,这个layout实际是包含它的两个child,看看代码:
package com.cat.slidelayout;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Interpolator;
import android.widget.Scroller;
/**
*
* @author huangjun
*
*/
public class SlideLayout extends ViewGroup {
private final static int TOUCH_STATE_REST = 0;
private final static int TOUCH_STATE_SCROLLING = 1;
private int mTouchState = TOUCH_STATE_REST;
private boolean mFirstLayout = true;
private Scroller mScroller;
private int mCurrentScreen;
private LayoutOvershootInterpolator mScrollInterpolator;
private GestureDetector mGDetector = null;
public SlideLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
initWorkspace();
}
public SlideLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setHapticFeedbackEnabled(false);
initWorkspace();
}
private void initWorkspace() {
Context context = getContext();
mScrollInterpolator = new LayoutOvershootInterpolator();
mScroller = new Scroller(context, mScrollInterpolator);
mGDetector = new GestureDetector(this.getContext(),
new WorkspaceOnGestureListener());
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
boolean g = mGDetector.onTouchEvent(ev);
if (mCurrentScreen == 1
&& ev.getX() + getChildAt(1).getWidth() < getWidth()
&& ev.getAction() == MotionEvent.ACTION_DOWN) {
snapToScreen(0, false);
return true;
}
if (g && ev.getAction() == MotionEvent.ACTION_UP) {
return true;
} else {
return super.onInterceptTouchEvent(ev);
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
// 先执行滑屏事件
boolean g = mGDetector.onTouchEvent(ev);
if (g &&