Android 滑动抽屉半打开时可点击的内容

Android 滑动抽屉半打开时可点击的内容,android,clickable,slidingdrawer,Android,Clickable,Slidingdrawer,我正在考虑在抽屉处于半关闭状态时实现一个具有可点击功能的半关闭滑动抽屉。然而,在关闭抽屉时,我发现图形可能已设置动画,但按钮的可单击区域仍保持在相同的位置。我尝试在slidingdrawer类的moveHandle()下的slider类中实现LayoutParams类、view.layout()和view.OffsetOpandBottom(),但没有成功。下面是moveHandle()方法的一个片段: private void移动句柄(int位置){ 最终视图句柄=mHandle; 最终视图内

我正在考虑在抽屉处于半关闭状态时实现一个具有可点击功能的半关闭滑动抽屉。然而,在关闭抽屉时,我发现图形可能已设置动画,但按钮的可单击区域仍保持在相同的位置。我尝试在slidingdrawer类的moveHandle()下的slider类中实现LayoutParams类、view.layout()和view.OffsetOpandBottom(),但没有成功。下面是moveHandle()方法的一个片段:

private void移动句柄(int位置){
最终视图句柄=mHandle;
最终视图内容=mContent;
如果(垂直){
如果(位置==扩展的\完全的\打开的){
handle.offsetTopAndBottom(mTopOffset-handle.getTop());
使无效();
}else if(位置==折叠\半关闭){
handle.offsetTopAndBottom(mBottomOffset+getBottom()-getTop())-
mHandleHeight-msemicClosedContentSize-handle.getTop();
使无效();
}否则{
final int top=handle.getTop();
int deltaY=位置-顶部;
如果(位置MBottomofset+getBottom()-getTop()-mhandlehight-msemicClosedContentSize-top){
deltaY=mBottomOffset+getBottom()-getTop()-mhandlehight-msemicclosedcontentsize-top;
}
手柄。偏置和底部(三角洲);
最终矩形帧=mFrame;
最终Rect区域=mInvalidate;
handle.getHitRect(frame);
区域集(帧);
联合(frame.left,frame.top-deltaY,frame.right,frame.bottom-deltaY);
region.union(0,frame.bottom-deltaY,getWidth(),
frame.bottom-deltaY+mContent.getHeight();
使(地区)无效;
}
有人有办法在关闭滑动抽屉时向下移动可点击按钮的位置吗

多谢各位


关于,

不推荐使用滑动抽屉,请参考

该类在API级别17中被弃用

这意味着谷歌不再支持它了,你不应该让它正常工作


我认为您应该尝试使用不同的实现。您可以寻找一个选项。

谢谢您的回复。我将尝试使用向上滑动面板进行替换。此外,我还发现了一个不太优雅的解决方案,即创建单独的按钮,仅在抽屉关闭时显示,同时隐藏滑动抽屉的内容。
private void moveHandle(int position) {
    final View handle = mHandle;
    final View content = mContent;

    if (mVertical) {
        if (position == EXPANDED_FULL_OPEN) {
            handle.offsetTopAndBottom(mTopOffset - handle.getTop());
            invalidate();
        } else if (position == COLLAPSED_SEMI_CLOSED) {
            handle.offsetTopAndBottom(mBottomOffset + getBottom()- getTop()-
                    mHandleHeight - mSemiClosedContentSize - handle.getTop());
            invalidate();
        } else {
            final int top = handle.getTop();
            int deltaY = position - top;
            if (position < mTopOffset) {
                deltaY = mTopOffset - top;
            } else if (deltaY > mBottomOffset + getBottom()- getTop()- mHandleHeight - mSemiClosedContentSize - top) {
                deltaY = mBottomOffset + getBottom()- getTop()- mHandleHeight - mSemiClosedContentSize - top;
            }
            handle.offsetTopAndBottom(deltaY);

            final Rect frame = mFrame;
            final Rect region = mInvalidate;

            handle.getHitRect(frame);
            region.set(frame);

            region.union(frame.left, frame.top - deltaY, frame.right, frame.bottom - deltaY);
            region.union(0, frame.bottom - deltaY, getWidth(),
                    frame.bottom - deltaY + mContent.getHeight());

            invalidate(region);
        }