0

I have images with dynamical dimensions and ImageView with statistical height. I'm trying to bind my image in my imageView like this.

ImageLink

Image I mean to fill the ImageView horizontally, but not vertically. Here is my code

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="280dp">
    <ImageView
        android:id="@+id/exploreImage"
        android:src="@drawable/beard1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

But there is now ScaleType in ImageView, that allows this way to bind.

Do you have any idea about how to do it?

kio_tk
  • 47
  • 7

2 Answers2

0

Place it inside a scrollview and change your imageview code to this:

<ImageView
    android:id="@+id/exploreImage"
    android:src="@drawable/beard1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true" 
/>
Dyna
  • 2,304
  • 1
  • 14
  • 25
  • Well, its a very nice idea, but it has a padding in the top of scrollView Oo – kio_tk Feb 14 '14 at 11:59
  • you can create your own class, this answer will help you a lot: http://stackoverflow.com/a/4688335/1182971 – Dyna Feb 14 '14 at 12:19
  • Nice, thank you a lot I've already found the solution without creating a new class. Just add to your answer android:adjustViewBounds="true" And I will accept it – kio_tk Feb 14 '14 at 12:28
  • Hah, I implemented this in my code, and than I have another trouble, can you help again? http://stackoverflow.com/questions/21783536/onitemclick-doesnt-work-if-there-is-scrollview-on-layout – kio_tk Feb 14 '14 at 16:14
  • you should have said that this is an item of your listview, listview and scrollview don't get along. – Dyna Feb 14 '14 at 17:20
  • Right, I had to notice it. Anyway I learned another way to do it) Now I will try to create a new class.. – kio_tk Feb 14 '14 at 17:37
0

Following xml produces very similar output to what you want. Just give the desired height lower than the height of the image.

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="100dp"
    android:scaleType="matrix"
    android:src="@drawable/image_1" />

In fact, ScaleType.Matrix means scaling using the image matrix which you should later provide in code when drawing. When you set scaleType="matrix" but provide no matrix in code; then it does not scale but crop the image starting from top.

Timuçin
  • 4,653
  • 3
  • 25
  • 34