亲爱的,我正在实施ALESSANDRO CRUGNOLA定制滑动抽屉。我希望它滑过屏幕的一半。我从右到左很容易做到这一点,但现在我想要从左到右。问题是,当第一个抽屉打开时,它一直向右滑动,然后突然回到我指定的中间点。关于如何解决这个问题的任何想法?指定中间点的代码如下,从左到右滑块的布尔值 mInvert 为真。
@Override
protected void onLayout( boolean changed, int l, int t, int r, int b )
{
if ( mTracking ) { return; }
final int width = r - l;
final int height = b - t;
final View handle = mHandle;
int handleWidth = handle.getMeasuredWidth();
int handleHeight = handle.getMeasuredHeight();
Log.d( LOG_TAG, "handleHeight: " + handleHeight );
int handleLeft;
int handleTop;
final View content = mContent;
//mTopOffset = getWidth()/2;
if ( mVertical ) {
handleLeft = ( width - handleWidth ) / 2;
if ( mInvert ) {
Log.d( LOG_TAG, "content.layout(1)" );
handleTop = mExpanded ? height - mBottomOffset - handleHeight : mTopOffset;
content.layout( 0, mTopOffset, content.getMeasuredWidth(), mTopOffset + content.getMeasuredHeight() );
} else {
handleTop = mExpanded ? mTopOffset : height - handleHeight + mBottomOffset;
content.layout( 0, mTopOffset + handleHeight, content.getMeasuredWidth(), mTopOffset + handleHeight + content.getMeasuredHeight() );
}
} else {
handleTop = ( height - handleHeight ) / 2;//centre alings the handle
if( mInvert ) {
mBottomOffset = getWidth()/2;//to limit the window sliding half way
handleLeft = mExpanded ? width - mBottomOffset - handleWidth : mTopOffset;
content.layout( mTopOffset, 0, mTopOffset + content.getMeasuredWidth(), content.getMeasuredHeight() );
} else {
mTopOffset = getWidth()/2;//to limit the window sliding half way
handleLeft = mExpanded ? mTopOffset : width - handleWidth + mBottomOffset;
content.layout( mTopOffset + handleWidth, 0, mTopOffset + handleWidth + content.getMeasuredWidth(), content.getMeasuredHeight() );
}
}
handle.layout( handleLeft, handleTop, handleLeft + handleWidth, handleTop + handleHeight );
mHandleHeight = handle.getHeight();
mHandleWidth = handle.getWidth();
}