私は現在、画像ビューを含むAndroidウィジェットを開発しています。ウィジェットはサイズ変更可能であると想定されています。
画像はウィジェットの幅全体(これは簡単な部分です)を満たし、ウィジェットの高さの30%を満たし、最大高さ80dipを尊重する必要があります(これは私にはわかりません)。
次のレイアウトでは、画像は高さではなく幅に適切に拡大縮小されます。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/widget_margin">
<ImageView
android:id="@+id/promoShelf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/shelf"
android:scaleType="fitXY"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
これを実現するために、ウェイト付きのLinearLayoutを使用しようとしました。これは、次のスニペットで確認できます。android:maxHeight
ただし、ウェイトを使用すると、尊重されないように見えます。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/widget_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical"
android:weight_sum="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dip"
android:maxHeight="80dip"
android:src="@drawable/my_image"
android:scaleType="fitXY"
android:layout_weight="0.3" />
</LinearLayout>
</RelativeLayout>
したがって、これは(不要な)結果です。
なぜmaxHeight
機能していないのですか、または誰かがこれを回避する方法を知っていますか?