更新时间:2022-12-05 17:33:50
如果我的理解以及自己添加的按钮,在您的SlidingDrawer手柄,你想他们的工作就像按钮,当用户preSS他们保持一个标准SlidingDrawer当手柄是pressed /拖?
If I understand well you have added buttons on your SlidingDrawer handle and you want them to work like buttons when the user press them with keeping a standard SlidingDrawer behaviour when the handle is pressed/dragged?
我刚刚解决了类似的问题。
I just solved a similar problem.
我的把手一直在寻找这样的事情:
My Handle was looking something like that:
它是由两个按钮和一个中心TextView的,这将是真正的手柄(反应为标准SlidingDrawer手柄)。
It's composed of two buttons and a center TextView which will be the real handle (reacting as a standard SlidingDrawer handle).
为使按钮独立SlidingDrawer的工作,我在标准SlidingDrawer.java类的onInterceptTouchEvent方法改了一下源$ C $ C(复制粘贴从Android code源的源文件):
To make the buttons work independently of the SlidingDrawer I changed a bit of source code in the onInterceptTouchEvent method of the standard SlidingDrawer.java class (copy paste the source file from the android code source):
public boolean onInterceptTouchEvent(MotionEvent event) {
//...
final Rect frame = mFrame;
final View handle = mHandle;
// original behaviour
//mHandle.getDrawingRect(frame);
// New code
View trackHandle = mTrackHandle;
// set the rect frame to the mTrackHandle view borders instead of the hole handle view
// getParent() => The right and left are valid, but we need to get the parent top and bottom to have absolute values (in screen)
frame.set(trackHandle.getLeft(), ((ViewGroup) trackHandle.getParent()).getTop(), trackHandle.getRight(), ((ViewGroup) trackHandle.getParent()).getBottom());
if (!mTracking && !frame.contains((int) x, (int) y)) {
return false;
}
//...
}
我还添加了一个二传手的mTrackHandle属性设置,活动创建过程中,真正的hanlde使用方法:
I also added a setter for the mTrackHandle attribute to set, during the activity creation, the real hanlde to use:
protected void onCreate(Bundle savedInstanceState) {
//...
mSlidingDrawer.setTrackHandle((View) findViewById(R.id.menu_handle_TextView_Title));
//...
}
之后,你可以在你的两个按钮设置标准的监听器。他们将工作就像一个魅力。
After that you can set standard listener on your two buttons. They will work like a charm.