LinearLayout을 확장하는 사용자 지정보기가 있습니다. 이 커스텀 뷰는 LinearLayout과 똑같은 레이아웃을 가져야 만하는 몇 가지 다른 뷰를 포함하고 있습니다. 그러나 나는 그것들을 올바르게 레이아웃 할 수 없었습니다 ... 모든 서브 뷰는 이전에 추가 된 모든 서브 뷰를 숨기고 서로 위에 놓습니다.LinearLayout을 확장하는 사용자 레이아웃에 대한 Onlayout 메서드
내 onLayout과 된 onMeasure 다음과 같이
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// Do nothing. Do not call the superclass method--that would start a layout pass
// on this view's children. PieChart lays out its children in onSizeChanged().
super.onLayout(changed, l, t, r, b);
Log.e(LOG_TAG, LOG_TAG + ".onLayout: " + l + ", " + t + ", " + r + ", " + b);
int iChildCount = this.getChildCount();
for (int i = 0; i < iChildCount; i++) {
View pChild = this.getChildAt(i);
pChild.layout(l, t, pChild.getMeasuredWidth(), pChild.getMeasuredHeight());
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Try for a width based on our minimum
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Log.d(LOG_TAG, LOG_TAG + ".onMeasure: width: " + widthMeasureSpec + " getWidth: " + MeasureSpec.getSize(widthMeasureSpec));
Log.d(LOG_TAG, LOG_TAG + ".onMeasure: height: " + heightMeasureSpec + " getHeight: " + MeasureSpec.getSize(heightMeasureSpec));
Log.d(LOG_TAG, LOG_TAG + ".onMeasure: getPaddingLeft: " + getPaddingLeft() + " getPaddingRight: " + getPaddingRight());
Log.d(LOG_TAG, LOG_TAG + ".onMeasure: getPaddingTop: " + getPaddingTop() + " getPaddingBottom: " + getPaddingBottom());
// http://stackoverflow.com/a/17545273/474330
int iParentWidth = MeasureSpec.getSize(widthMeasureSpec);
int iParentHeight = MeasureSpec.getSize(heightMeasureSpec);
this.setMeasuredDimension(iParentWidth, iParentHeight);
int iChildCount = this.getChildCount();
for (int i = 0; i < iChildCount; i++) {
View pChild = this.getChildAt(i);
this.measureChild(pChild,
MeasureSpec.makeMeasureSpec(iParentWidth, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(iParentHeight, MeasureSpec.EXACTLY)
);
}
}
어떻게 내 사용자 지정보기의 폭과 높이의 x 위치, Y 위치를 설정합니까? 내 사용자 지정보기의 LayoutParam을 WRAP_CONTENT로 설정했지만 여전히 FILL_PARENT처럼 작동하며 부모에서 사용 가능한 모든 여유 공간을 차지합니다. 위치 나 크기를 변경하려는 모든 노력이 전혀 효과가없는 것처럼 보입니다. (심지어 위치를 제어하려고 시도해도 포장을하려고 시도했습니다.)