do not know what to do to make viewpage can be normal in listview sliding around it ?
------ Solution ---------------------------------------- ----
rewrite ListView ListView touch time estimates processed their hair down a sliding time not because it is not a ViewGroup View ; consumer touch time so you do not need to continue the viewpage issued are not receiving touch events ( no actual analysis may be different or wrong for reference only )
------ Solution ------------------------------------------- -
http://download.csdn.net/detail/shen332401890/5290671
------ eference --------------------- ------------------
this how to write ah , how to solve it ? ? ?
------ eference ------------------------------------ ---
intercept response onTouchEvent handle horizontal sliding events on the line
public class ViewPagerInListView extends ViewPager {
public ViewPagerInListView(Context context) {
super(context);
}
public ViewPagerInListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public boolean onInterceptTouchEvent(MotionEvent arg0)
{
//当拦截触摸事件到达此位置的时候,返回true,
//说明将onTouch拦截在此控件,进而执行此控件的onTouchEvent
return true;
}
/** 触摸时按下的点 **/
PointF downP = new PointF();
/** 触摸时当前的点 **/
PointF curP = new PointF();
public boolean onTouchEvent(MotionEvent arg0) {
//每次进行onTouch事件都记录当前的按下的坐标
curP.x = arg0.getX();
curP.y = arg0.getY();
if(arg0.getAction() == MotionEvent.ACTION_DOWN){
downP.x = arg0.getX();
downP.y = arg0.getY();
getParent().requestDisallowInterceptTouchEvent(true);
}
if(arg0.getAction() == MotionEvent.ACTION_MOVE){
float dx = Math.abs(arg0.getX()-downP.x);
float dy = Math.abs(arg0.getY()-downP.y);
if (dy<dx)
{
//此句代码是为了通知他的父ViewPager现在进行的是本控件的操作,不要对我的操作进行干扰
getParent().requestDisallowInterceptTouchEvent(true);
}
else
{
getParent().requestDisallowInterceptTouchEvent(false);
}
}
if(arg0.getAction() == MotionEvent.ACTION_UP){
getParent().requestDisallowInterceptTouchEvent(false);
float dx = Math.abs(arg0.getX()-downP.x);
float dy = Math.abs(arg0.getY()-downP.y);
if (dy<dx)
{
// 向右
if (arg0.getX()-downP.x>0)
{
what.getAndAdd(-1);
if (what.get() < 0) {
what.getAndAdd(imageViews.size());
}
viewHandler.sendEmptyMessage(what.get());
}
else
{
what.incrementAndGet();
if (what.get() > imageViews.size() - 1) {
what.getAndAdd(-imageViews.size());
}
viewHandler.sendEmptyMessage(what.get());
}
}
if (dx==0&&dy==0)
{
Intent intent = new Intent();
intent.putExtra("id",""+curTitleShowId);
intent.putExtra("title",""+curTitle);
intent.putExtra("typeTilte",""+title);
intent.setClass(act, NewsInfoActivity.class);
act.startActivity(intent);
act.overridePendingTransition(R.anim.push_left_in,R.anim.push_left_out);
}
}
return super.onTouchEvent(arg0);
}
}
没有评论:
发表评论