我在我的 Android 项目中使用 Glide 库来更新来自 API 响应的 URL 中的头像。
问题是,当我尝试将不同的图像(来自不同的 URL)加载到相同imageView的图像时,它会向我显示第一次下载的图像。(URL形成工作正常,我在浏览器中尝试过,它显示了所需的图像)
这是我的代码: EditProfileFragment.xml
public static final String IMAGE_BASE_URL = "http://myapi.com/img/";
String imageUrl = Const.IMAGE_BASE_URL + cb_getProfile.photo; //imageName.jpg
Glide.with(mContext)
.load(imageUrl)
.animate(R.anim.abc_fade_in)
.centerCrop()
.into(mImageView_photo);
Run Code Online (Sandbox Code Playgroud) 我已经加载远程图像ImageView使用下面的代码
Glide.with(context)
.load(imageUrl)
.placeholder(R.drawable.placeholderImage)
.into(holder.wallPaperImageView);
Run Code Online (Sandbox Code Playgroud)
现在我想从imageview获取位图
Bitmap bitmap = ((GlideBitmapDrawable)holder.wallPaperImageView.getDrawable()).getBitmap();
Run Code Online (Sandbox Code Playgroud)
但上面的代码行抛出异常:
java.lang.ClassCastException:android.graphics.drawable.TransitionDrawable无法强制转换为com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable
怎么解决这个?
我想显示来自 HTML 的图像,并且我使用Jsoup. 但是,一个问题是每个帖子都有不同数量的图片。所以,我无法修复 xml 布局中 ImageView 的数量。经过研究,我知道我可以动态创建ImageViews。所以,我创建ImageViews并将它们插入到 Linearlayout. 但是,我只能看到我最后插入的一张图片。
package kr.ac.mju.hanmaeum.activity.notice;
import android.content.Intent;
import android.media.Image;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import kr.ac.mju.hanmaeum.R;
import kr.ac.mju.hanmaeum.activity.BaseActivity;
import kr.ac.mju.hanmaeum.utils.Constants;
public class NoticeContent extends BaseActivity {
private String url, title, timestamp, content = "";
private TextView timestampView, titleView;
private ImageView contentImageView, contentImageView2;
private …Run Code Online (Sandbox Code Playgroud) 我正在使用Glide库进行图像加载.我的应用程序中有很多图像,所以我想在缓存大小超过50 MB时清除缓存.有人可以帮我这样做吗?
我的应用程序中的多个活动都有用户的个人资料图片。有一次,他们更改了个人资料图片,我想确保我的所有 Glide 实例的缓存都被清除。这样,当他们浏览应用程序时,他们可以看到更新的个人资料图片。
目前我正在使用这种方法:Glide.get(activity).clearDiskCache();这只会清除该活动的 Glide 缓存,而不是在我的应用程序中清除。
希望有人有一个快速的解决方案,我不需要为每个活动中的每个滑翔实例调用 .signature() 函数。或者清除每个活动中的每个滑行缓存。
我希望将我的应用程序从 Glide v3 升级到 Glide v4。我需要知道gif通过 Glide 加载的循环有多长。
v3 代码:
int duration = 0;
GifDecoder decoder = gifDrawable.getDecoder();
for (int i = 0; i < gifDrawable.getFrameCount(); i++) {
duration += decoder.getDelay(i);
}
Run Code Online (Sandbox Code Playgroud)
看起来GifDecoderGlide v4 不再公开。没有它我如何计算这个,或者我现在如何获得解码器?
'gradle''import'已经完成。然后我有一个问题。救命。
D:\bg.jou\GanggoContacts\build.gradle
Error:(25, 13)
Failed to resolve: com.android.volley:volley:1.1.0
<a href="openFile:D:/bg.jou/GanggoContacts_v34_insert_error/build.gradle">Show in File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
Error:(26, 13)
Failed to resolve: com.github.bumptech.glide:glide:3.7.0
<a href="openFile:D:/bg.jou/GanggoContacts_v34_insert_error/build.gradle">Show in File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
Run Code Online (Sandbox Code Playgroud)
不完整的问题
buildscript {
repositories {
jcenter()
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.0'
}
}
Run Code Online (Sandbox Code Playgroud)
dependencies {
//compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services-gcm:11.8.0'
compile fileTree(include: '*.jar', dir: 'libs')
compile project(':fingerpush_3.0.7')
compile 'com.android.volley:volley:1.1.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
}
Run Code Online (Sandbox Code Playgroud) 我在约束布局中使用 imageview 并希望 ImageView 的宽度是屏幕的宽度和高度根据图像是动态的。
我的布局 XML 是
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 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"
style="@style/CardView.Light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/newsItemBackground"
tools:layout_editor_absoluteY="29dp">
<TextView
android:id="@+id/textTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:textColor="@color/textHighEmphasis"
android:textSize="@dimen/news_title_size"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Title" />
<TextView
android:id="@+id/textTime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:fontFamily="@font/english_font"
android:textColor="@color/textMediumEmphasis"
android:textSize="@dimen/news_time_size"
android:textStyle="normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textTitle"
tools:text="Time" />
<Button
android:id="@+id/buttonMore"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/buttonShare"
app:layout_constraintTop_toBottomOf="@+id/viewSeperator"
app:layout_constraintVertical_bias="0.0"
tools:text="readmore" />
<Button
android:id="@+id/buttonShare"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@string/share_button" …Run Code Online (Sandbox Code Playgroud) 我正在使用Glide 4.8.0版本
对于加载图像,我这样做
GlideApp
.with(HomePageFragment.this)
.load(remoteURL)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(mImageView);
Run Code Online (Sandbox Code Playgroud)
当设备连接到Internet时,映像成功加载,但是当设备脱机时,如何从已经从缓存中获取的缓存中加载相同的映像remoteURL?
我的CustomAppGlideModule看起来像这样
@GlideModule
public class CustomAppGlideModule extends AppGlideModule {
@Override
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
builder.setMemoryCache(new LruResourceCache(20 * 1024 * 1024));
builder.setDiskCache(new InternalCacheDiskCacheFactory(context, 100 * 1024 * 1024));
}
}
Run Code Online (Sandbox Code Playgroud)
我也试过
.onlyRetrieveFromCache(true)
Run Code Online (Sandbox Code Playgroud)
但这也无济于事。
我正在尝试将图像从 firebase 加载到回收器适配器中并显示它们
我尝试了两种方法来尝试解决此问题,第一个代码块导致错误“您无法在尚未附加的视图或片段上启动加载,其中 getActivity() 返回 null(通常在 getActivity() 时发生在附加 Fragment 之前或在 Fragment 销毁之后调用)”
应用程序运行的第二种方法,但没有通过阅读其他类似问题加载图像我已经看到 isAdded() 检查,但我似乎无法让它工作图像被上传到 firebase 中名为 post_images 的文件夹中,其余的与帖子相关的数据(Instagram 之类的发布应用程序)在 firestore 中
public BlogRecyclerAdapter(List<BlogPost> blog_list) {
this.blog_list = blog_list;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.blog_list_item, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
String desc_data = blog_list.get(position).getDesc();
holder.setDescText(desc_data);
String image_url = blog_list.get(position).getImage_url();
holder.setBlogImage(image_url);
}
@Override
public int getItemCount() {
return blog_list.size();
}
public …Run Code Online (Sandbox Code Playgroud)