因此,我终于弄清楚是否其他人对此有疑问。基本上,当您想调整布局大小时,您需要调整大小measure()
后的布局。如果没有offsetLeftAndRight()
调用,句柄将在一瞬间“跳转”到新的大小,因此设置偏移量可以消除“跳转”。
我所做的简化版本基本上是:
public void resize() {
int previousPosition = mHandle.getLeft();
//Set the new size of the content area
mContent.getLayoutParams().width = width;
//Measure the newly sized content area and adjust the layout
mContent.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(getBottom() - getTop(), MeasureSpec.EXACTLY));
mContent.layout(handleWidth + mTopOffset, 0, mTopOffset + handleWidth + content.getMeasuredWidth(), content.getMeasuredHeight());
/* Remeasure any other views that were resized also here */
//Not required but helps position the handle correctly
mHandle.offsetLeftAndRight(previousPosition);
}