아래 레이아웃 xml에서 두 개의 자식 뷰가있는 가로 LinearLayout
을 만듭니다. LinearLayout
아동은 너비를 동적으로 늘려야하는데, ImageView
은 부모의 높이에 따라 너비가 있습니다.layout_weight를 다시 계산하는 방법은 무엇입니까?
하지만 실제로 얻을 것은 :
이 있기 때문이다
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<!-- Some children ... -->
</LinearLayout>
<MyAspectRatioImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true" />
</LinearLayout>
이제 내가 무엇을 달성하기 위해 노력하고있어이 같은 결과는 내 사용자 정의 ImageView
1 : 1 종횡비 (단순화)를 유지하기 위해 onMeasure
을 오버런했습니다.
override def onMeasure(widthMeasure: Int, heightMeasure: Int)
{
super.onMeasure(widthMeasure, heightMeasure)
setMeasuredDimensions(height, height)
}
이제 새로운 ImageView 너비를 고려하여 너비 공유를 다시 계산하려면 부모보기가 필요합니다. 어떻게해야합니까?