我想在我的应用程序中显示动画GIF图像.正如我发现的那样,Android本身并不支持动画GIF.
但是它可以使用AnimationDrawable显示动画:
该示例使用在应用程序资源中保存为帧的动画,但我需要的是直接显示动画gif.
我的计划是将动画GIF分解为帧并将每个帧添加为可绘制到AnimationDrawable.
有谁知道如何从动画GIF中提取帧并将它们转换为Drawable?
我有一个小型动态壁纸应用程序,我想添加支持它来显示GIF动画.
为此,我找到了各种解决方案.有一种在视图(这里)中显示GIF动画的解决方案,甚至还有一个解决方案,可以在动态壁纸(这里)中显示它.
但是,对于它们两者,我无法找到如何在其所拥有的空间中很好地拟合GIF动画的内容,这意味着以下任何一种情况:
这些都不是关于ImageView的,所以我不能只使用scaleType属性.
有一个解决方案可以为你提供一个GifDrawable(这里),你可以在ImageView中使用它,但在某些情况下它似乎很慢,我无法弄清楚如何在LiveWallpaper中使用它然后适合它.
LiveWallpaper GIF处理的主要代码就是这样(这里):
class GIFWallpaperService : WallpaperService() {
override fun onCreateEngine(): WallpaperService.Engine {
val movie = Movie.decodeStream(resources.openRawResource(R.raw.cinemagraphs))
return GIFWallpaperEngine(movie)
}
private inner class GIFWallpaperEngine(private val movie: Movie) : WallpaperService.Engine() {
private val frameDuration = 20
private var holder: SurfaceHolder? = null
private var visible: Boolean = false
private val handler: Handler = Handler()
private val drawGIF …Run Code Online (Sandbox Code Playgroud) 您好stackoverflow我正在尝试开发一个Android应用程序来玩我自己的GIF,这里是代码片段
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Run Code Online (Sandbox Code Playgroud)
AnimationView.java
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.util.AttributeSet;
import android.view.View;
public class AnimationView extends View {
private Movie mMovie;
private long mMovieStart;
private static final boolean DECODE_STREAM = true;
private int mDrawLeftPos;
private int mHeight, mWidth;
private static byte[] streamToBytes(InputStream is) {
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
byte[] buffer = new byte[1024];
int …Run Code Online (Sandbox Code Playgroud) 我想将一张 gif 放入我的应用程序中。我知道如何插入图像资源,但是当我尝试添加 gif 时,它变成了静态图像。
DrawImage(image = +imageResource(R.drawable.gif))
Run Code Online (Sandbox Code Playgroud)
有没有人尝试过在 Jetpack Compose 中添加 gif,因为很难在网上找到如何添加 gif 文档?
我的布局有很多图像视图.我想在一个imageview中显示.gif动画文件.我尝试了Yash方法(在Android中的ImageView中添加gif图像),但.gif文件显示了所有布局.其他观点消失了.
我要展示所有.
任何的想法?
如何将GIF格式图像添加为启动画面.我试图添加,但当我添加它.它充当正常图像.我不知道我们是否可以使用Gif图像作为启动画面.如果有任何选项可以使用该GIF格式图像.
我需要一些有关动画的建议。我有一个动画GIF,但是如何将Android应用程序变成动画。当我说的时候,它根本没有动。我读了一些有关Android动画的知识,并且需要有动画图片。有什么解决办法吗?
我正在使用此库显示gif图像:https : //github.com/felipecsl/GifImageView
但是我不知道如何在这些代码中实现我的gif图像。我在素材资源文件夹中有一些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 …Run Code Online (Sandbox Code Playgroud) 我正在使用这里给出的GifWebView
我知道主要活动等工作正常,因为我在用于框架布局的XML实现之前测试了它.但是现在我正在使用Frame Layout,我遇到了问题.
我将为您提供我的代码和快速解释:
XML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.example.dencallanan.giftestapp.GifWebView
android:id="@+id/GWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<RelativeLayout 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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_marginBottom="153dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:hint="USERNAME" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:layout_marginTop="58dp"
android:layout_alignTop="@+id/editText"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText"
android:hint="PASSWORD" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Log In"
android:id="@+id/button"
android:layout_below="@+id/editText2"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp" />
</RelativeLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
GifWebView
public class GifWebView extends WebView {
public GifWebView(Context context, String path) {
super(context);
loadUrl(path);
}
public GifWebView(Context …Run Code Online (Sandbox Code Playgroud)