zoukankan      html  css  js  c++  java
  • android -- 加载gif 防止oom

    项目中涉及到gif图片的展示,原来使用的是gifview,但是当频繁的,加载过大图片的时候会出现OOM的问题,后来去github上面找相关的库:

    https://github.com/koral--/android-gif-drawable

    android-gif-drawable是比较好的,并能尽最大可能避免oom的库

    下面讲下如何导入和使用该库:

    这些事so文件,必须导入;还有就是引入jar包:

    然后xml文件里面:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/loading_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <pl.droidsonroids.gif.GifImageView
            android:id="@+id/iv_loading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="@dimen/dimen_48dp" />
    
        <TextView
            android:id="@+id/tv_iv_nonet_bg1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/iv_loading"
            android:layout_centerHorizontal="true"
            android:text="加载中.."
            android:textColor="@color/color_A3A3A3" />
    
    </RelativeLayout>

    注意红色部位就是对应加载gif图片的控件GifImageView

    下面看下代码中如何使用:

    GifImageView gifView = (GifImageView) findViewById(R.id.iv_loading);
            gifView.setImageResource((R.drawable.search_loading_bg));

    第二行就是加载drawable的代码,至于其他用法,看该库github

  • 相关阅读:
    Stream流之三级查询
    SpringBoot日期格式的设置
    el表达式
    SpringMV+HuTool之验证码登录
    Spring注解详解
    @ResponseBody注解使用(返回字符串并不跳转)
    每日leetcode-数组-589. N 叉树的前序遍历
    python apply函数
    剑指offer-JZ6 旋转数组的最小数字
    torch.manual_seed()函数
  • 原文地址:https://www.cnblogs.com/androidsuperman/p/4988084.html
Copyright © 2011-2022 走看看