私はImageViewの高さと幅を固定しています(幅100dp、高さ50dp)。この画像ビューに画像を動的にロードする必要があります。イメージを幅に合わせてアンドロイドでアスペクト比を維持する方法
この画像をImageViewの幅に塗りつぶしても、縦横比を維持するように拡大します(高さの限界のために画像の一部が見えない場合は気にしません)。
私が欲しいものはcenterCrop
と本当に似ていますが、私は自分のイメージを垂直にセンタリングしたくありません!
ありがとうございます。
EDIT1:
は、ここに私のコードです:
これは私のレイアウトです。私はbackground
idでimageViewの画像を設定したいと思います。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/footer"
android:layout_alignBottom="@id/footer"
/>
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="100dp">
</RelativeLayout>
ImageViewの第二RelativeLayoutの大きさにバインドされていることに注意してください:
android:layout_alignTop="@+id/footer"
android:layout_alignBottom="@id/footer"
drawableをビットマップに変換せずにこの正確なことを行うことは可能でしょうか?それは私の使用のために本当に遅いです。 –
私はこれを正確に探していたのですか? +1 – instanceof