입니다. ViewGroup
을 새로 만듭니다. 새보기에는 일부 서클이 그려집니다. 뷰에는 5 개의 초기 원이 있어야하기 때문에 뷰의 너비에 걸쳐 고르게 퍼뜨려보기 (뷰의 중심이 (x, y) 위치) 일 때 다시 그려야합니다. 무효화 됨.크기를 기준으로 사용자 정의 레이아웃을 그리는시기는
이것은 내 onMeasure
: 나는이 원을 추가해야 할 때
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
int desiredWidth = getPaddingLeft() + getPaddingRight() + PREFERED_SIZE;
int desiredHeight = getPaddingTop() + getPaddingBottom() + PREFERED_SIZE;
actualWidth = resolveSizeAndState(desiredWidth,widthMeasureSpec,0);
actualHeight = resolveSizeAndState(desiredHeight,heightMeasureSpec,0);
setMeasuredDimension(actualWidth, actualHeight);
}
내가 잘 모르겠어요 것은. onMeasure
여러 번 호출 할 수 있으며 다른 너비 및 높이 값을 얻을 수 있으므로 언제 계산해야합니까 (x, y) 초기 동그라미. onMeasure
? onDraw
? 처음에?
onMeasure와 거의 비슷하게 보입니까? –
정확하게 'onMeasure'는'onLayoutChange'보다 더 많이 호출됩니다. onMeasure는 부모 뷰가 레이아웃을 계산할 때마다 호출되며, onLayoutChange는 특정 뷰의 레이아웃이 변경 될 때 호출됩니다. –