我对GIF调整大小有疑问。我的GIF尺寸是136*136
px,我正在尝试使用Glide库将其加载到图像视图中(其宽度和高度设置为wrap_content
)。但GIF最终会占据整个屏幕。我的XML文件代码段如下所示:
ImageView
android:id="@+id/loading_animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
tools:src="@drawable/gif_loading_animation"
android:foregroundGravity="center" />
我的主要活动代码看起来像这样:
Glide.with(getContext())
.load(R.drawable.gif_loading_animation)
.asGif()
.into(loadingAnimation);
是否有任何解决方案可以避免在不使用任何硬代码参数宽度和高度的情:)
你可以尝试使用.override(Target.SIZE_ORIGINAL)
Glide.with(getContext())
.load(R.drawable.gif_loading_animation)
.asGif()
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.into(loadingAnimation);