Ich habe ein Problem mit der Darstellung eines Landschaftsbildes ohne centerCrop. Ich versuchte PercentFramelayout
, und legen Sie Seitenverhältnis programmatisch wie folgt aus:Bildformat programmatisch für imageView setzen
laParams.percentLayoutInfo.aspectRatio = img.width.toFloat()/img.height.toFloat()
Das Ergebnis ist ok - die Anwendung alle Landschaftsbilder ohne centerCrop zeigte:
Aber manchmal bekomme ich die falsches Seitenverhältnis:
Ich versuchte android:adjustViewBounds ="true"
, aber es hilft mir nicht. Und ich verwenden ConstraintLayout
, das Seitenverhältnis in XML wie diese Einstellung:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
>
<android.support.v7.widget.AppCompatImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/photo"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="h,16:9"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</android.support.constraint.ConstraintLayout>
Ich habe gutes Ergebnis, aber ich Bilder unterschiedliche Größe laden. Bilder sollten ohne CenterCrop
und FitXY
sein. Ich fand keine guten Antworten über das eingestellte Seitenverhältnis programmatisch für Constraintlayout
Ich möchte Bilder wie Instagram oder Vk zeigen.