我正在使用这个 library作为显示“gif”文件的指南。在 drawable
中使用保存的 gif
时,它会正确显示 gif
我这样调用它
<pl.droidsonroids.gif.GifImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgView1"
android:src="@drawable/gifFile"
/>
但是当删除 src
并尝试像这样在 Activity 中初始化 GifImageView 时
GifImageView gifFromFile = (GifImageView) findViewById(R.id.imgView1);
gifFromFile.setImageBitmap(Utils.getBitmapImagefromStorage(context, imageHome));
其中 getBitmapImagefromStorage
获取路径,imageHome
获取文件名 gif 文件不会像图像一样播放它的唯一显示。据说如果给定的 drawable 不是 GIF,然后提到 View 像普通 ImageView 和 ImageButton 一样工作。
但我提供的文件是 gif
。我想知道如果我正确使用它。
文件也可以是 png
或 gif
所以我需要支持这两者。
最佳答案
GifTextView gifImageView;
在onCreate中
gifImageView = (GifTextView) findViewById(R.id.imageView);
在onCreate中调用此方法
public void playGif(){
Animation fadeout = new AlphaAnimation(1.f, 1.f);
fadeout.setDuration(2500); // You can modify the duration here
fadeout.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
gifImageView.setBackgroundResource(R.drawable.gif_image);//your gif file
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
});
gifImageView.startAnimation(fadeout);
}
在你的布局文件中
<pl.droidsonroids.gif.GifTextView
android:id="@+id/imageView"
android:layout_width="fill_parent"
android:scaleType="fitXY"
android:layout_height="fill_parent"
/>
关于android - 如何显示GIF文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39888939/