У меня есть пользовательский вид, расширяющий LinearLayout. Это настраиваемое представление содержит несколько других представлений, которые должны располагаться точно так же, как LinearLayout, однако мне не удалось правильно их раскрыть ... Все подзадачи лежат друг на друге, скрывая все ранее добавленные надстройки.Метод Onlayout на пользовательском макете, расширяющем LinearLayout
Мои 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)
);
}
}
Как установить й-позицию, у-позицию, ширину и высоту моего настраиваемого представления? Я установил LayoutParam своего пользовательского представления в WRAP_CONTENT, однако он по-прежнему ведет себя как FILL_PARENT, занимая все свободное пространство, доступное в родительском. Кажется, что все мои усилия по изменению положения или размера вообще не работают (я даже пытаюсь установитьPadding, чтобы попытаться управлять позицией)