5

I want to diplay an image so that it takes up a minmum width of the screen and should scale in its aspect ratio (the image width might be smaller or larger than the minimun width) I also want to have a fixed size border around this image. This is my xml section for it:

<ImageView
        android:id="@+id/detailed_view_boxArt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minWidth="150dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/detailed_view_heading"
        android:padding="10dp"
        android:layout_marginLeft="5dp"
        android:scaleType="centerInside"

        android:background="#000"/> 

This however does not produce what I want...the problem is that it does not scale the image horizontally far enough (ie. the 10px padding that I have seems a lot more on the right and left)

How would I produce the result that I want?

Kman
  • 2,569
  • 5
  • 23
  • 27

2 Answers2

4

to set minimum width and heidht use the attributes android:minHeight="100dip" and android:minWidth="200dip".

to set the Border check my post.

Community
  • 1
  • 1
Praveen
  • 90,477
  • 74
  • 177
  • 219
  • Thanks for the info...however the way I have created the border works just aswell as your method. The problem is I want to ONLY set a minWidth and have the image stretch both horizontally and vertically... – Kman Jul 20 '10 at 10:48
  • @Kman: Can not get you properly. my guess is you to set the value for your `android:layout_width="100dip"` not `wrap_content`. – Praveen Jul 20 '10 at 11:15
  • no no my xml is exactly like the code I have in the question...Ok basically I want to make the image larger/smaller while keeping its aspect ratio so that it ends up with a minimum width of 150dp. So for example lets say I have an image of 50dp wide 100dp high I want it so that it shows the image as 150dp wide 300dp high. Is that clearer? Thanks – Kman Jul 20 '10 at 11:31
  • @Kman: Thats great idea. I have to research on it. when get answer. let you know. – Praveen Jul 20 '10 at 16:49
3

Try this (I emphasized the important part):

<ImageView
    android:id="@+id/detailed_view_boxArt"
    *android:layout_width="match_parent"*
    *android:layout_height="wrap_content"*
    *android:adjustViewBounds="true"*
    *android:scaleType="centerCrop"*                   
    android:layout_alignParentLeft="true"
    android:layout_below="@id/detailed_view_heading"
    android:padding="10dp"
    android:layout_marginLeft="5dp"
    android:background="#000"/> 
Andrii Chernenko
  • 9,873
  • 7
  • 71
  • 89
  • Also keep in mind **scaleType centerInside** if you don't want you images to *overflow*; see http://developer.android.com/reference/android/widget/ImageView.ScaleType.html – m02ph3u5 Apr 16 '15 at 14:56