Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageView ScaleType ignores padding

I have a Imageview set with a white background and 1dp padding, this creates a border-like effect, which is the wanted result.

Now if I set the scaleType to centerCrop it ignores the padding on the top and bottom.
So I still have my border on the left and right side, but not on the top and bottom.

Anyone with an idea to stop this from happening? Or another quick way to create a border around images. I use it for my custom gridview

   <ImageView             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:layout_weight="1"             android:background="#FFFFFF"             android:contentDescription="@string/test"             android:padding="1dp"             android:src="@drawable/some_photo"             android:scaleType="centerCrop" /> 
like image 576
TheLD Avatar asked Jun 01 '12 13:06

TheLD


1 Answers

<ImageView     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:layout_weight="1"     android:contentDescription="@string/test"     android:padding="1dp"     android:src="@drawable/some_photo"     android:cropToPadding="true"     android:scaleType="centerCrop" /> 

You only need to add android:cropToPadding

android:cropToPadding="true"

and then the imageView is going to respect the padding that you choose.

like image 165
Manolo Garcia Avatar answered Nov 08 '22 20:11

Manolo Garcia