我在.gif文件上的firebase存储中有链接
String gifUrl = "https://firebasestorage.googleapis.com/v0/b/rokitskiydev-a18ca.appspot.com/o/WF%2F10-16-02-Digital-15.gif?alt=media&token=0354f6e6-4292-4911-9302-49281d293a80";
我尝试使用毕加索和滑行。但是我只能显示此gif的图像。
GlideApp.with(context).load(gifUrl).into(ImageView);
如果我获得了另一个链接,则示例http://i.imgur.com/1ALnB2s.gif
没关系!
我该怎么做?
获取GIF的 downloadurl ,然后用它加载GIF。
ImageView imageView = (ImageView) findViewById(R.id.imageView);
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
Glide.with(this).load(downloadUrl).into(imageViewTarget);
对于新版本的滑行版,请尝试以下方法:
Glide.with(context)
.load(imageUrl)
.asGif()
.placeholder(R.drawable.loading2)
.crossFade()
.into(imageView);
正如Glide文档所说的,
您可以使用.asGif()
迫使库加载动画gif,如果不是:
Glide.with(activity).load(gifUrl).asGif().into(view);
尝试这个
检查文档:https://futurestud.io/tutorials/glide-displaying-gifs-and-videos
也是Firebasedoc所说,您可以这样做以加载带有滑行的图像/gif
首先在您的build.gradle
中声明这一点dependencies {
// FirebaseUI Storage only
compile 'com.firebaseui:firebase-ui-storage:0.6.0'
}
然后
这是用firebase加载图像
// Reference to an image file in Firebase Storage
StorageReference storageReference = ...;
// ImageView in your Activity
ImageView imageView = ...;
// Load the image using Glide
Glide.with(this /* context */)
.using(new FirebaseImageLoader())
.load(storageReference)
.into(imageView);
如果您需要图像/GIF文件的URL,则可以执行此操作
storageRef.child("your/firebase/imagepath.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// Got the download URL for 'users/me/profile.png'
Uri downloadUri = taskSnapshot.getMetadata().getDownloadUrl();
generatedFilePath = downloadUri.toString(); /// The string(file link) that you need
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});