Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android how to make ImageView with a minWidth have a border?

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?

like image 770
Kman Avatar asked Jul 16 '10 09:07

Kman


People also ask

Can ImageView be clickable?

You can make a view clickable, as a button, by adding the android:onClick attribute in the XML layout. For example, you can make an image act like a button by adding android:onClick to the ImageView .


2 Answers

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

to set the Border check my post.

like image 105
Praveen Avatar answered Sep 27 '22 19:09

Praveen


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"/> 
like image 26
Andrii Chernenko Avatar answered Sep 27 '22 19:09

Andrii Chernenko