해당 뷰의 두 배 신장 된 뷰 (사용자 정의 뷰 DayView
)가 필요합니다.이 뷰에는 두 개의 중첩 뷰 중 하나가 다른 사용자 정의 뷰입니다. 사용자 지정보기는 모두 RelativeLayout
에서 확장됩니다.사용자 정의 뷰의 하위 크기를 올바르게 조정하는 방법
레이아웃이 같다 :
<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
정확한 크기는하지만, 두 개의 중첩 된 뷰는 부모와 함께 스트레치하지만, 사용하지 않는 것있다 a wrap_content
높이 레이아웃 규칙
질문
어떻게이 두 가지 중첩 된 뷰는 부모 DayView
와 같은 높이를 인수 할 수 있습니까?
이 줄을 지우고 다시 시도하십시오.'super.onMeasure (widthMeasureSpec, heightMeasureSpec); ' –
@JimitPatel : 작동하지 않습니다. 창이 더 이상 두 배 이상 크기가 아니며, 아이들은 더 이상 보이지 않습니다. 전혀 그려지지 않았다. – Marcel50506
그런 다음'parentHeight * 2'를 만들어'setMeasuredDimension()'메소드에 넘겨 줘라. 어디에서나 수정 된 값을 사용하십시오. 또한,'setLayoutParams()'와'super.onMeasure()'를 제거하십시오. 왜냐하면 나는 일반적으로'setMeasuredDimension()'메소드를 다른 언급 된 메소드없이 사용하기 때문에 나를 위해 작동한다. –