2013-09-06 5 views
0

현재 SlidingDrawer 클래스를 확장하고 있으며 내용의 너비를 조정하려고하는데 제대로 작동하지 않습니다. 지금은 전체보기 (핸들 및 내용)의 너비를 설정하고 크기 조정 목적으로 작동하지만 핸들을 움직이면 시각적 결함이 발생하여 분할 된 새 크기로 점프 한 다음 핸들로 돌아갑니다. 위치. 컨텐트 영역의 크기가 조정되지는 않지만 완전히 확신 할 수없는 기본 SlidingDrawer에서 발생하는 onMeasure() 또는 onLayout() 호출로 인해 문제가 발생한다고 생각합니다.SlidingDrawer 내용 너비를 동적으로 변경하십시오.

전체보기의 크기를 조정하는 데 getLayoutParams().width = newWidth;을 사용하고 있지만 mContent.getLayoutParams().width = newWidth;과 같은 것을 사용하고 싶습니다.

onMeasure()의 소스 코드는 here이고 onLayout()here의 소스 코드입니다.

콘텐츠 영역의 크기를 조정할 수없는 이유에 대한 통찰력이 우수합니다. 감사!

답변

0

다른 누군가가이 문제를 겪고있는 경우 마침내 알아 냈습니다. 기본적으로 레이아웃 크기를 조정하려는 경우 크기가 변경된 후 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); 
} 
관련 문제