Fit Image / Bitmap to ImageView or adjust ImageView to Image / Bitmap

2

I'm trying to create a menu screen something like this:

Tomakethiscutdiagonally,Imadethisimagetostayontopofthebackground:

However,inAndroidStudio,Icannotscaletheimagetofilltherequiredspaceonthescreen,I'musingConstraintLayoutandtryingtoenlargetheimage,evenwitha>highresolutionitlookslikethis:

Itdoesnotincreaseright,I'vealreadytriedtotweakvarioussettingslike:ScaleType,AdjustViewBounds,cropToPadding,I'malldaybehinditNothingsofar

FollowherXMLcode:

<ImageViewandroid:id="@+id/imageView"
    android:layout_width="616dp"
    android:layout_height="449dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:srcCompat="@mipmap/ic_diag" />
    
asked by anonymous 29.10.2017 / 01:35

1 answer

0

When setting absolute values for android:layout_width and android:layout_height ImageView will be displayed with these dimensions.

  • If you want ImageView to fit the dimensions of the layout it should use match_parent and possibly android:adjustViewBounds="true" .

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:srcCompat="@mipmap/ic_diag" />
    
  • If you want the image to fit the ImageView size you may need to use one of the android: scaleType . The type to use will depend on the size and shape of the image and the final result you want to obtain (with or without deformation, cropped image or not).

29.10.2017 / 12:57