繁体   English   中英

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

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

我想将Gif显示为背景图像上的上层。 究竟我想要在背景和图像中拥有图像我还想要显示gif但是当我运行代码时我只看到gif背景图像被隐藏,有人可以告诉我现在应该怎么做

我的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>

我在GifImage视图和布局背景中都使用了背景图像,但在两种情况下它都没有显示背景。

这可以通过相对布局实现一个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>

为什么你只看到GIF图像,而不是你的背景图像?

因为

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"

注意:您也可以在线将当前的GIF转换为透明GIF。

希望这能以某种方式帮助你。

暂无
暂无

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

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