java - 如何在android studio中的背景图像上显示gif
问题描述
我想将 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>
推荐阅读
- python - 迭代非插值符号数组python等效
- postgis - 如何从postgis中的缓冲点集合制作多边形
- mysql - MySQL 优化连接
- ios - 更新 MKMapRect 扩展的 Swift 语法
- vba - IIf 在 IIf 内分配变量值
- python-3.x - 来自脚本的 zgrep S3 存储桶
- javascript - Spotfire HTML 表格 - 具有变量值的条件格式
- html - 如何在 CSS 中使脱节图像的大小相同?
- python - 多游标数据库连接 Python
- teamcity - Teamcity buildpath 更改 nativescript 项目名称