图像视图折叠,不显示创建的缩略图



我正在尝试拍摄用户可以在应用程序中查看的视频的缩略图图像,并将其显示在ImageView中。但是,当我尝试显示缩略图时,看起来整个 ImageView 消失了,根本没有出现任何图像。

我尝试使用不是缩略图的测试照片,它肯定显示在 ImageView 中,所以我认为这不是 XML 的问题,但它可能是。我已经用谷歌搜索了几个小时,不明白我在哪里搞砸了。我的代码已经来自堆栈溢出。

uri = Uri.parse("android.resource://"+ getActivity().getPackageName() +"/"+R.raw.test);
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(uri.getPath(), Thumbnails.MICRO_KIND);
//Create ImageView to hold the thumbnail
ImageView imageView = view.findViewById(R.id.mediaPreview);
imageView.setImageBitmap(thumb);

.XML

    <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/startup_dialog"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_weight="25"
  tools:context=".ui.MainActivity">
    <TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="@string/getting_started"
      android:gravity="start"
      android:layout_gravity="start"/>
    <ImageView
      android:id="@+id/mediaPreview"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_marginHorizontal="20dp"
      android:layout_marginTop="10dp"
      />

图像将显示,但它没有显示,因为您可能有一个像素更大的图像,请尝试更改图像像素或尝试添加另一个图像。

最新更新