Java Android - crop image in ImageView

I know this should be simple, but android:scaleType="centerCrop" does not android:scaleType="centerCrop" image

I got an image with a width of 1950 pixels and needed to crop it to the width of the parent. But android:scaleType="centerCrop" dosen't crop Image. What do I need to do in the layout to show only the first 400 pixels, for example, or any screen / parent width -

Sorry for the simple question - tried google - there are only complicated questions. And I'm a newbie, so don't let down plz)

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/rl1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/background_color"> <ImageView android:id="@+id/ver_bottompanelprayer" android:layout_width="match_parent" android:layout_height="227px" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:scaleType="matrix" android:background="@drawable/ver_bottom_panel_tiled_long" /> </RelativeLayout> 
+6
source share
2 answers

Try adding android:adjustViewBounds="true" to your ImageView along with the android:scaleType

+1
source

Use android:scaleType="matrix" for your image

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/opLayout" android:layout_width="400px" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:id="@+id/bar" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="matrix" android:src="@drawable/ic_launcher_web" /> </LinearLayout> 
+1
source

Source: https://habr.com/ru/post/951692/


All Articles