【问题标题】:how to show gif image as a background in relative layout如何在相对布局中将 gif 图像显示为背景
【发布时间】:2016-03-23 16:54:34
【问题描述】:
我有一个动画 gif 图像,我想将其显示为相对布局的背景。我使用了一个由视图扩展的活动并为此使用了电影类,但它并没有解决我的问题。请提出任何建议。
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:components="http://schemas.android.com/apk/res/com.example.YourPakageName"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.example.YourPakageName.GIFView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
components:src="@drawable/congratulations" />
</LinearLayout>
【问题讨论】:
标签:
android
animation
view
gif
【解决方案2】:
Android 不支持 gif。
您可以使用一些图像加载器插件,如 Glide 或 Picasso 用于这些目的。您必须将 gif 保存在 assets 文件夹中,或者保存在服务器中。
【解决方案3】:
是的,您可以设置 gif 图像,但这不会为您的 gif 图像设置动画。您需要将 gif 图像显式提取到所有帧中,然后将图像动画化为 gif。
click hear
【解决方案4】:
如果您想将按钮放在播放的 GIF 上方,这是代码。
在 RelativeLayout 放置第一个 ImageView 与 android:layout_width="match_parent"
android:layout_height="match_parent"
然后根据您的要求另一个 ImageView 或 Button 。最后一个显示在 GIF 上方。然后使用 Glide Library 来展示。
<RelativeLayout
android:id="@+id/rel_music_play"
android:layout_width="wrap_content"
android:layout_height="180dp"
>
- <ImageView
android:id="@+id/imageViewGifPlaying"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:layout_centerInParent="true"
android:src="@drawable/ray_music_icon"
/>
<ImageView
android:id="@+id/btn_play"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:src="@drawable/play_round_icon" />
</RelativeLayout>
Glide.with(this)
.load(R.drawable.stream_animation)
.asGif()
.into(imageViewGifPlaying);