按钮上的滑动抽屉? - 机器人抽屉、机器人、按钮

2023-09-05 08:56:15 作者:沵湜莪哋洤蔀

欧凯,让我实现了在一个Android应用程序我建立一个滑动抽屉的按钮。唯一的问题是,当我preSS按钮,整个滑动抽屉pressed,它滑了起来。

Okey, so I've implemented a button on a Sliding drawer in a android application I'm building. The only problem is that when I press the button the whole sliding drawer is pressed and it slides up.

我知道我可以禁用'preSS向上滑动中的XML,但似乎并没有工作的滑动抽屉仍然是pressed只是不滑了。

I know I can disable 'press to slide up' in the XML, but that does not seem to work as the sliding drawer still is pressed just without the slide up.

如果我所说的slidingDrawer.lock();功能按钮的实际工作,但随后的滑动抽屉不能向上滑动,甚至是pssed高达$ P $。

If I call the slidingDrawer.lock(); function the button actually works but then the sliding drawer can't slide up or even be pressed up.

任何一个有一个简单的解决这个问题呢?

Any one have a simple solution to this problem?

推荐答案

如果我的理解以及自己添加的按钮,在您的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.