简体   繁体   English

如何在android studio中显示背景图像上的gif

[英]how to show gif on background image in android studio

I want to show Gif as a upper layer on background image. 我想将Gif显示为背景图像上的上层。 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 究竟我想要在背景和图像中拥有图像我还想要显示gif但是当我运行代码时我只看到gif背景图像被隐藏,有人可以告诉我现在应该怎么做

My XML Code is Here 我的XML代码就在这里

<?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. 我在GifImage视图和布局背景中都使用了背景图像,但在两种情况下它都没有显示背景。

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: 这可以通过相对布局实现一个imageview,并将其高度和宽度设置为match_parent,然后将背景添加到该imageview,最后在图像视图下方添加你的gif视图,它基本上将它对齐在imageview的顶部,这应该可以做到这一点:

<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? 为什么你只看到GIF图像,而不是你的背景图像?

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. 注意:您也可以在线将当前的GIF转换为透明GIF。

Hope this help you somehow. 希望这能以某种方式帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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