Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

Inside an ImageView, how can I align the image to the bottom, horizontally center it, and scale it to fill the ImageView, maintaining aspect ratio in android ?

By M.K. Verma · 4 May 2022

Inside an ImageView, how can I align the image to the bottom, horizontally center it, and scale it to fill the ImageView, maintaining aspect ratio in android ?
<LinearLayout
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginTop="20dp"
    android:gravity="bottom|center_horizontal"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/title"
    app:layout_constraintBottom_toBottomOf="parent">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:scaleType="fitEnd"
        />

</LinearLayout>