Android 如何在相对布局中将gif图像显示为背景

Android 如何在相对布局中将gif图像显示为背景,android,animation,view,gif,Android,Animation,View,Gif,我有一个动画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="fi

我有一个动画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>
LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android"
xmlns:components=”http://schemas.android.com/apk/res/com.example.YourPakageName"
android:layout\u width=“fill\u parent”
android:layout\u height=“fill\u parent”
android:orientation=“vertical”>

Android不支持gif。 您可以使用一些图像加载器插件,如或用于这些目的。您必须将gif保存在资产文件夹或服务器中。

您可以使用Glide


可以,您可以设置gif图像,但这不会设置gif图像的动画。您需要显式地将gif图像提取到所有帧中,然后使用动画将图像设置为gif。

如果您想将按钮放在GIF播放上方,则这是代码。 在RelativeLayout下,使用android放置第一个ImageView:layout\u width=“match\u parent” android:layout\u height=“match\u parent” 然后根据您的要求选择另一个ImageView或按钮。最后一个显示在GIF上方。然后使用Glide库来显示

        <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);

-       
用(这个)滑翔
.load(R.drawable.stream_动画)
.asGif()
.进入(游戏);
        <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);