Gif动态图片库--GifView的基本使用

GifView 的基本功能:

   为了解决android中现在没有直接显示gif的view,只能通过mediaplay来显示这个问题的项目,其用法和 ImageView一样,支持gif图片。可监视GIF是否加载成功。

GifView的功能:

  • 播放Gif图片
  • Gif动画监听

创建Android工程GifViewDemo来介绍一下:

首先添加GifView库和ImageLoader库的gradle依赖:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.github.Cutta:GifView:1.1'
    compile 'com.zftlive.android.library:feature-android-imageloader:1.0.0'
}

然后在drawable中添加gif图:



接着进行布局activity_main设置:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.dpl.gifviewdemo.MainActivity">

    <com.cunoraz.gifview.library.GifView
        android:id="@+id/gifView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>



最后在MainActivity.java中调用:

package com.example.dpl.gifviewdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.cunoraz.gifview.library.GifView;

/*
加载本地GIF图片,使用gifView
 */
public class MainActivity extends AppCompatActivity {
    private GifView gifView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gifView= (GifView) findViewById(R.id.gifView);
        //设置图片源
        gifView.setGifResource(R.drawable.wanshengjie);//本地图片
        //位置设置
        gifView.setX(150);
        gifView.setY(300);
    }
}

运行结果:


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值