0

I'am working on some Android stuff and I have encountered weird problem with image scaling. The image that you you can see in the image below has:

<ImageView
            android:id="@+id/imagePreview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/editor_placeholder"
            android:contentDescription="@string/stfu" />

And i keep asking myself why are those black stripes present. Can i make it to display the image without those stripes?

SOLUTION:

android:adjustViewBounds="true"

Got rid off unnecessary stripes.

enter image description here

Haito
  • 2,039
  • 1
  • 24
  • 35
  • use `android:scaleType`. There are different enums that will do different things. Have a look at http://developer.android.com/reference/android/widget/ImageView.ScaleType.html and http://www.techrepublic.com/article/clear-up-ambiguity-about-android-image-view-scale-types-with-this-guide/ – kha Nov 17 '15 at 16:27

3 Answers3

2

Sure you can do this a few different ways. If you want the image to fit and don't care about the crop of the image you can do something like:

   <ImageView
        android:id="@+id/imagePreview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        android:src="@drawable/editor_placeholder"
        android:contentDescription="@string/stfu" />

there are various different ImageView.ScaleType for an ImageView:

CENTER -> Center the image in the view, but perform no scaling. From XML, use this syntax: android:scaleType="center".

CENTER_CROP -> Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding). The image is then centered in the view. From XML, use this syntax: android:scaleType="centerCrop".

CENTER_INSIDE -> Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding). The image is then centered in the view. From XML, use this syntax: android:scaleType="centerInside".

FIT_CENTER -> Scale the image using CENTER. From XML, use this syntax: android:scaleType="fitCenter".

FIT_END -> Scale the image using END. From XML, use this syntax: android:scaleType="fitEnd".

FIT_START -> Scale the image using START. From XML, use this syntax: android:scaleType="fitStart".

FIT_XY -> Scale the image using FILL. From XML, use this syntax: android:scaleType="fitXY".

FIT_MATRIX -> Scale using the image matrix when drawing. The image matrix can be set using setImageMatrix(Matrix). From XML, use this syntax: android:scaleType="matrix".

Here is a nice article from the developer site to help with programmatic scaling

kandroidj
  • 13,784
  • 5
  • 64
  • 76
0

use android imageview scale type property inside imageview in xml file ..

android:scaleType="fitXY".
vishal jangid
  • 2,967
  • 16
  • 22
0

Try this

<ImageView
        android:id="@+id/imagePreview"
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        android:scaleType="centerCrop"
        android:src="@drawable/editor_placeholder"
        android:contentDescription="@string/stfu" />
Collins Abitekaniza
  • 4,496
  • 2
  • 28
  • 43