Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 用库显示Gif图像大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用此库来显示gif图像: https://github.com/felipecsl/GifImageView

但我不知道如何在这代码中实现我的gif图像.我在资产@L_874_6@夹中有一些GifImages.

这是我的代码

PlayActivity.java:

import android.app.Activity;
import android.os.bundle;

import com.felipecsl.gifimageview.library.GifImageView;

import java.io.IOException;
import java.io.InputStream;

public class PlayActivity extends Activity{

    GifImageView gifView;
    //byte[] bytes;

    @Override
    protected void onCreate(final Bundle savedInstanceStatE) {
        super.onCreate(savedInstanceStatE);
        setContentView(R.layout.layout_play_activity);

        try {
            InputStream is = getAssets().open("rain_4.gif");
            byte[] bytes = new byte[is.available()];
            is.read(bytes);
            is.close();

            gifView = (GifImageView) findViewById(R.id.gifImageView);
            gifView = new GifImageView(this);
            gifView.setBytes(bytes);
            gifView.startAnimation();
        } catch (IOException E) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        if(gifView != null) gifView.startAnimation();
    }

    @Override
    protected void onStop() {
        super.onStop();
        if(gifView != null) gifView.startAnimation();
    }
}@H_944_14@ 
 

和layout_play_activity.xml:

<LinearLayout xmlns:android="http://scheR_55_11845@as.android.com/apk/res/android"
    xmlns:tools="http://scheR_55_11845@as.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context=".PlayActivity">

    <com.felipecsl.gifimageview.library.GifImageView
        android:id="@+id/gifImageView"
        android:layout_gravity="center"
        android:scaleType="fitCenter"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>@H_944_14@

解决方法

您提供的图书馆链接中有一个示例.加载GifImageView的方式与示例中的方式不同.样本从互联网上下载了一个gif.

以下是样本的MainActivity的片段:

GifImageView gifImageView = (GifImageView) findViewById(R.id.gifImageView);

new GifDataDownloader() {
    @Override
    protected void onPostExecute(final byte[] bytes) {
        gifImageView.setBytes(bytes);
        gifImageView.startAnimation();
        Log.d(tag,"GIF width is " + gifImageView.getGifWidth());
        Log.d(tag,"GIF height is " + gifImageView.getGifHeight());
    }
}.execute("http://gifs.joelglovier.com/aha/aha.gif");@H_944_14@ 
 

解:

我不确定您是否可以使用此库从资产加载GifImageView,但我更喜欢使用离子库.这真的很好很简单.使用该库,您还可以根据需要拉伸gif图像:

https://github.com/koush/ion

简单示例:

ImageView imageView = (ImageView) findViewById(R.id.imageView);
Ion.with(imageView).load("http://gifs.joelglovier.com/aha/aha.gif");@H_944_14@

大佬总结

以上是大佬教程为你收集整理的android – 用库显示Gif图像全部内容,希望文章能够帮你解决android – 用库显示Gif图像所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。