Dynamische Änderung der ImageView-Höhe
Ich habe ein einfaches lineares Layout für die ListView-Zelle, und es hat eine Bildansicht. Das Bild wird aus dem Internet heruntergeladen, daher kann die Größe unterschiedlich sein.
Ich möchte jedoch die Breite der Bildansicht auf fill_parent setzen, was fest ist, und die Bildhöhe zur Laufzeit dynamisch ändern. Regeln zum Einstellen der Bildhöhe: Wenn das H / W-Verhältnis des Bildes mehr als 1 beträgt, stellen Sie das ImageView-Quadrat ein, dh passen Sie die Höhe an die Breite an.
Wenn das H / W-Verhältnis des Bildes kleiner als 1 ist, vergrößern Sie es proportional. Erwarten Sie zwei Beispiele wie folgt.
Das erste ist h / w <1, während das zweite 'Cat' h / w> 1 ist.
Vielen Dank für Ihre Zeit.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
android:padding="10dp" >
<TextView
android:id="@+id/postTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/postImg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:scaleType="centerCrop"
android:src="@drawable/dummy_image"
android:contentDescription="@string/postImage" />
</LinearLayout>