-1

i have an animated gif image which i want to show as a background of relative layout. I used an activity extended by view and used movie class for that but it did not solve my problem. pls any suggetion will be appriciated.

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>
Bhargav Thanki
  • 4,708
  • 2
  • 34
  • 43
Pavan Verma
  • 11
  • 2
  • 2
  • http://stackoverflow.com/questions/15762990/is-it-possible-to-set-an-animated-gif-file-as-background-of-my-app-in-android – koutuk Dec 17 '15 at 09:38

4 Answers4

2

you can use Glide https://github.com/bumptech/glide

Glide.with(context)
.load(imageUrl)
.asGif()
.placeholder(R.drawable.loading2)
.crossFade()
.into(imageView);
MinFu
  • 353
  • 1
  • 13
1

Android doesn't support gif. You can use some image loader plugin like Glide or Picasso for these purposes. You have to keep the gif in the assets folder, or in a server then.

Rivu Chakraborty
  • 1,272
  • 2
  • 12
  • 35
0

Yes, you can set the gif image but this will not animate your gif image. You need to explicitly extract the gif image into all frame and then using animate you image as gif. click hear

Community
  • 1
  • 1
Krunal Patel
  • 129
  • 3
  • 12
0

This is the code if you want to put the button above the GIF playing. under RelativeLayout place first ImageView with android:layout_width="match_parent" android:layout_height="match_parent" and then another ImageView or Button as per your requirement . the last one show above the GIF. and then use Glide Library to show .

        <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);
Avinash Ajay Pandey
  • 1,407
  • 12
  • 18