0
尊敬的各位,我正在實施ALESSANDRO CRUGNOLA定製滑動抽屜。我希望它滑過屏幕一半。我很輕易就做到了這一點,但現在我想從左到右。問題是,當抽屜第一次打開時,它一直滑到右側,然後回到我指定的中間點。關於如何解決這個問題的任何想法?用於指定中途點的代碼位於下方,左側至右側滑塊的布爾mInvert爲true。SlidingDrawer從左至右發行
@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();
}