如何让缩略图适合图像视图?
我正在从刚刚录制的视频中获取缩略图,并且我需要使缩略图适合图像视图。我用它来调用缩略图:
Bitmap curThumb = ThumbnailUtils.createVideoThumbnail(file.getAbsolutePath(), MediaStore.Video.Thumbnails.MINI_KIND);
我用它来调用图像视图:
image.setImageBitmap(curThumb);
我的图像视图的 xml 看起来像这样:
<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>
我用于图像视图背景的边框是一个 xml,它给视图带来了很好的效果白色边框,这是它的以下 xml:
<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>
我不知道是否是因为我使用的是 MINI_KIND 缩略图,但我需要将其缩小一点,以便它可以完美地适合图像视图。任何帮助就足够了。提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将
android:scaleType="fitCenter"
添加到 ImageView 的属性中。这将使图像居中并确保(假设它大于 ImageView 的区域)图像覆盖整个区域,并且图像沿至少一个轴完全可见。
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.
将缩放类型设置为 centercrop http://developer.android.com/参考/android/widget/ImageView.html#attr_android:scaleType
Set your scaletype to centercrop http://developer.android.com/reference/android/widget/ImageView.html#attr_android:scaleType