简体   繁体   中英

how to show gif on background image in android studio

I want to show Gif as a upper layer on background image. What exactly i want to have image in background and on that image i also want to show gif but when i run the code i am only seeing the gif background image is hidden can someone tell what should i do now

My XML Code is Here

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ice"
tools:context=".MainActivity">

<pl.droidsonroids.gif.GifImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/gif"
    android:background="@drawable/ice"

    /></android.support.constraint.ConstraintLayout>

i have used background image in both GifImage view and also in Layout background but in both case its not showing background.

This can be implemented with relative layout take a imageview and set it's height and width as match_parent after that add background to that imageview lastly add your gif view below image view which will basically align it on top of the imageview this should do the trick:

<Relativelayout>
<Imageview 
android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/ice"/>
<pl.droidsonroids.gif.GifImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"  //layout added at last will be shown on top
    android:src="@drawable/gif"
    android:background="@drawable/ice"

    />
</Relativelayout>

Why you are seeing GIF Image only, not your background image?

Because

1) You are setting "width and height" of your GIF image as "match_parent" hence its 
   taking entire screen and you are not been able to see your background image.

2) Still if you want to set your GIF image as match_parent(that Ok!), make sure you 
   use "alpha GIF image or I would say transparent GIF image"

Note: You can convert your current GIF to transparent GIF online as well.

Hope this help you somehow.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM