Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Android - cropping Image in ImageView [duplicate]

I know this should be simple , but android:scaleType="centerCrop" doesn't crop Image

I got image 1950 pixels wide and need it to be cropped by parent's width. But android:scaleType="centerCrop" dosen't crop Image. What do I need to do in layout to show only first 400 pixels, for instance or whatever screen/parent width is

Sorry for simple question - tried to google it - only complicated questions there. And I'm new, so dont downvote 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>
like image 207
user2234594 Avatar asked Aug 14 '13 07:08

user2234594


2 Answers

Try adding android:adjustViewBounds="true" to your ImageView together with android:scaleType property

like image 136
Boris Mocialov Avatar answered Oct 17 '22 22:10

Boris Mocialov


Use android:scaleType="matrix" for your imageview

<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>
like image 44
Arun C Avatar answered Oct 17 '22 21:10

Arun C