2
在下面的佈局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
我覆蓋onMeasure
保持1:1的縱橫比(簡化):
override def onMeasure(widthMeasure: Int, heightMeasure: Int)
{
super.onMeasure(widthMeasure, heightMeasure)
setMeasuredDimensions(height, height)
}
現在我需要父視圖重新計算新的ImageView寬度的寬度共享。我怎樣才能做到這一點?