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

问题描述 投票:0回答:2

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

java android android-imageview
2个回答
0
投票

为什么你只看到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。

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


0
投票

这可以通过相对布局实现一个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>
© www.soinside.com 2019 - 2024. All rights reserved.