Android将Gif图片设置为背景------android-gif-drawable开源框架的使用

有了android-gif-drawable这个开源框架,在项目中使用gif动态图片不再是问题。 android-gif-drawable的 
开源地址是:https://github.com/koral–/android-gif-drawable。其主要作用就是可以展示gif格式的图片及动画,还可以对动画进行监听操作。开源库中封闭了GifImageView,GifImageButton,GifTextView等控件。和我们普通的ImageView,ImageButton,TextView使用方法基本一样,只要在布局文件中添加这些控件,然后就可以直接设置gif图片作为背景等。 
首先在AndroidStudio中配置相关依赖库代码,在配置文件build.gradle文件中添加:

   dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.+'
} 
  • 1
  • 2
  • 3
  • 4
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
    tools:context=".LoginActivity">
    <pl.droidsonroids.gif.GifImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/login_bg"
        />


</FrameLayout>

其中项目中的图片是我在百度上随便找的一张gif格式 的图片,运行效果就是手机上有两张动态图片,其中一张上有文字“这个TextView的背景好酷”。



  • 1
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值