centerCropを使用せずに風景画像を表示する際に問題があります。 私はPercentFramelayout
を試してみました、と設定アスペクト比がプログラムによってこのような :imageViewのプログラムでアスペクト比を設定する
laParams.percentLayoutInfo.aspectRatio = img.width.toFloat()/img.height.toFloat()
結果はokです - アプリケーションはcenterCropなく、すべての風景画像を示した:
しかし、時には私が手アスペクト比が間違っている:
私はandroid:adjustViewBounds ="true"
を試しましたが、それは私を助けません。 そして、私はこのようなXMLでアスペクト比を設定し、ConstraintLayout
を使用:
<?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>
私は良い結果を得たが、私は、画像に異なるサイズをロードします。画像はCenterCrop
とFitXY
なしである必要があります。私は設定されたアスペクト比についてプログラム的に良い答えが見つかりませんConstraintlayout
私はinstagramやvkのような画像を表示したいと思います。