的孩子我需要一个视图(自定义视图称为DayView
)绵延两次滚动视图的高度,它在,这种观点认为,有两个嵌套的意见,其中之一是另一个自定义视图。自定义视图全部从RelativeLayout
延伸。如何正确调整customview
的布局是这样的:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Is twice the size as scrollView, see code below -->
<com.example.DayView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Should be same size as parent DayView -->
<include layout="@layout/layout_dayplan_background"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<!-- Should be same size as parent DayView -->
<com.example.BlockView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</com.example.DayView>
</ScrollView>
两个嵌套视图(include
和BlockView
)应当具有相同的高度作为父DayView
。
在DayView
,我重写onMeasure使其两倍。这工作:(见“* 2”在倒数第二排)
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
this.setMeasuredDimension(parentWidth, parentHeight);
this.setLayoutParams(new ScrollView.LayoutParams(parentWidth, parentHeight * 2));
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
的DayView
有正确的尺寸,但是,这两个嵌套视图不与父母一起STRETCH时,但似乎使用一个wrap_content
高度布局规则。
问题
我怎样才能让这两个嵌套视图接管相同的高度父DayView
?
尝试删除此行后'super.onMeasure(widthMeasureSpec,heightMeasureSpec);' –
@JimitPatel:这不起作用,窗口似乎不再是尺寸的两倍,而且孩子们也没有一点都不画。 – Marcel50506
然后生成'parentHeight * 2'并将其传递给'setMeasuredDimension()'方法。随处使用修改后的值。另外,删除'setLayoutParams()'和'super.onMeasure()'。因为我一般用'setMeasuredDimension()'没有其他提到的方法方法,它为我的作品 –