ama*_*pid 29 user-interface android
我想在Android应用程序中显示动画GIF图像,如下图所示.我尝试过webview但没有成功.如何在应用程序中显示动画gif?
Ryu*_*uZz 29
您还可以使用此lib轻松支持gifDrawable.
只需使用GifImageView而不是普通的ImageView:
<pl.droidsonroids.gif.GifImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/your_anim"/>
Run Code Online (Sandbox Code Playgroud)
并在src attr下找到你的gif文件.就这样!
mle*_*kiy 18
你可以使用Glide:
ImageView imageView = (ImageView) findViewById(R.id.imageView);
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
Glide.with(this).load(R.raw.sample_gif).into(imageViewTarget);
Run Code Online (Sandbox Code Playgroud)
我尝试了很多库来使用 Animated gif 。但每个图书馆都落后且不堪重负。但现在,经过一两天的研究,我有了一个使用动画 gif 的想法,并且性能非常好,没有滞后,没有压垮。
解决方案是使用Glide
请按照以下步骤操作。
在 xml 文件中。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#62b849"
tools:context=".MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/splace_image_view"
android:layout_centerInParent="true"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
并在你的java文件中
ImageView imageView = findViewById(R.id.splace_image_view);
Glide
.with(this)
.load(R.drawable.football)
.into(imageView);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
77203 次 |
| 最近记录: |