ImageView折叠并且不显示创建的缩略图

时间:2019-07-18 15:39:33

标签: java android xml imageview

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

我尝试使用不是缩略图的测试照片,并且肯定将其显示在ImageView中,所以我认为XML并不是问题,但有可能。我已经在Google搜寻了几个小时,却不知道自己在哪里。我的代码已经来自Stack Overflow。

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"
      />

1 个答案:

答案 0 :(得分:0)

该图像将显示,但未显示,因为您的图像可能像素更大,请尝试更改图像像素或尝试添加其他图像。

相关问题