Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a thumbnail to fit inside an imageview?

I am getting thumbnails from a video that i just recorded and I need to get the thumbnail to fit into an imageview. I am using this to call the thumbnail :

Bitmap curThumb = ThumbnailUtils.createVideoThumbnail(file.getAbsolutePath(), MediaStore.Video.Thumbnails.MINI_KIND);

And I am using this to call the imageview:

image.setImageBitmap(curThumb);

My xml for my imageview looks as such:

<ImageView android:id="@+id/iView" android:paddingRight="10px" android:layout_height="280dp" android:layout_width="320dp" android:layout_gravity="center_horizontal" android:paddingTop="5dp" android:paddingBottom="5dp" android:background="@drawable/border"></ImageView>

The Border that I am using for my background of the image view is an xml which gives the view a nice white border frame, this is follwing xml for it:

<shape xmlns:android="http://schemas.android.com/apk/res/android" shape="oval">

    <stroke android:width="3dp" android:color="#ffffff" />
    <padding android:left="0px" android:top="1dp" android:right="0px"
        android:bottom="1dp" />
    </shape>

I don't know if its because I am using a MINI_KIND thumbnail but i need to cut it down by a little so it can fit into the imageview perfectly. Any help will suffice. Thanks in advance.

like image 593
user875139 Avatar asked Dec 04 '25 14:12

user875139


1 Answers

Try adding android:scaleType="fitCenter" to the ImageView's attributes.

This will center the image and ensure that (assuming it's larger than the ImageView's area) the image covers the entire area and that the image is completely visible along at least one axis.

like image 187
Greyson Avatar answered Dec 07 '25 04:12

Greyson