Android studio 使用 ImageView 加载 gif 文件

使用一个开源的图片加载和缓存的第三方框架 Android Glide 。

一、首先下载相应的 jar 包。

https://github.com/bumptech/glide/releases/download/v3.6.0/glide-3.6.0.jar

将 jar 包放进 libs 文件夹中,再导进工程中。

二、将 gif 文件放进 drawable 文件夹中

三、再 layout 中加入以下代码

    <ImageView
        android:id="@+id/welcome_gif"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"/>

其中,

 android:scaleType="fitXY"

 是为了适应屏幕,充满整个屏幕,android:scaleType 还有很多其他取值。

 四、相应的 Activity 中,在onCreate 中加入以下代码

        ImageView welcome_gif = (ImageView) findViewById(R.id.welcome_gif);
        Glide.with(this).load(R.drawable.welcome_mutouren).into(welcome_gif);

 其中,R.id.welcome_gif 是 ImageView 的 id 号;R.drawable.welcome_mutouren 是放入的gif 文件

 (图片来自 ui 中国)

 

 博客参考:https://blog.csdn.net/zhangphil/article/details/45535693

猜你喜欢

转载自www.cnblogs.com/lyw-hunnu/p/12151807.html