SlidingUpPanel的使用

来源:互联网 发布:正当防卫3优化怎么样 编辑:程序博客网 时间:2024/05/16 18:57

下载地址:https://github.com/umano/AndroidSlidingUpPanel

最近项目中使用过这种控件,调用的方法expandPanel(float offset);该方法主要设置打开的程度。以此,在背景处并不能响应点击事件,从而使得这个控件收拢,看了看这个View的事件处理方法中,从而获知,其中有一个方法:



private boolean isDragViewUnder(int x, int y) {
View dragView = mDragView != null ? mDragView : mSlideableView;
if (dragView == null)
return false;


int[] viewLocation = new int[2];
dragView.getLocationOnScreen(viewLocation);


int[] parentLocation = new int[2];
this.getLocationOnScreen(parentLocation);


int screenX = parentLocation[0] + x;// 0
int screenY = parentLocation[1] + y;// 113


return screenX >= viewLocation[0]&& screenX < viewLocation[0] + dragView.getWidth()
&& screenY >= viewLocation[1]
&& screenY < viewLocation[1] + dragView.getHeight();
}

通过各种点击,各种Log数据统计,发现该方法是计算一个范围,也就是类似于SlidingUpPanelLayout的底部View的,也就是第二个子View的头的位置范围。至于,怎么调用打开,合并的方法很清晰。在方法中isDragViewUnder的范围很小,在调用expandPanel(float offset)方法打开程度,上面会出现一部分的背景效果,然而,给人的第一操作印象便是点击这一块的背景效果区。至于,合拢的情况下,是没有背景效果区的,完全打开的时候也没有背景效果区,只是在打开成都在(0,1)区间会出现,要想在背景区+第二个子View的头区域中的范围点击效果有效,需要在此方法中再进行一次判断,方法如下:



private boolean isDragViewUnder(int x, int y) {
View dragView = mDragView != null ? mDragView : mSlideableView;
if (dragView == null)
return false;


int[] viewLocation = new int[2];
dragView.getLocationOnScreen(viewLocation);


int[] parentLocation = new int[2];
this.getLocationOnScreen(parentLocation);


int screenX = parentLocation[0] + x;// 0
int screenY = parentLocation[1] + y;// 113


//背景区域+第二个子View的点击。。。
if (isAnchored() && screenX >= viewLocation[0]
&& screenX < viewLocation[0] + dragView.getWidth()
&& y < viewLocation[1] + dragView.getHeight()) {
collapsePane();
return false;
} else {
return screenX >= viewLocation[0]
&& screenX < viewLocation[0] + dragView.getWidth()
&& screenY >= viewLocation[1]
&& screenY < viewLocation[1] + dragView.getHeight();
}
}

可能 y < viewLocation[1] + dragView.getHeight()这个条件不是很完美,但是,功能还是实现了。望赐,更好的处理方式。谢谢!

0 0
原创粉丝点击