我在这里做错什么了吗?我想加载该灰色作为占位符,但是它不加载。似乎只有在已经设置或加载了另一个图像的情况下才会发生。
Glide.with(getContext())
.load(url)
.placeholder(new ColorDrawable(ContextCompat.getColor(getContext(), R.color.placeholder_gray)))
.error(new ColorDrawable(ContextCompat.getColor(getContext(), R.color.placeholder_gray)))
.dontAnimate()
.into(new SimpleTarget<GlideDrawable>() {
@Override
public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
image.setImageDrawable(resource);
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
resetImageView();
}
});
Run Code Online (Sandbox Code Playgroud) 所以我遇到了一个问题,即使是加载图像的最简单的实现也Glide无法工作,并且导致 AppX 停止。我什至创建了一个侧应用程序,其中仅包含从 URL 加载所需的必要代码,但它不起作用。我尝试了几个我知道有效的 URL,但遇到了同样的问题。我已经添加了权限:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE">
</uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Run Code Online (Sandbox Code Playgroud)
梯度指令:
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:support-v4:23.0.0'
Run Code Online (Sandbox Code Playgroud)
我的活动 XML 如下所示:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
tools:context="com.example.benhouse.basicglidetest.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="138dp"
android:layout_height="495dp"
android:orientation="horizontal"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:layout_editor_absoluteX="192dp"
tools:layout_editor_absoluteY="155dp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
和我的 .java 用于该活动:
package com.example.benhouse.basicglidetest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
public class MainActivity extends AppCompatActivity {
ImageView imageView;
@Override
protected …Run Code Online (Sandbox Code Playgroud) 我想使用glide将一个图像显示为两个不同的图像视图。我知道我可以简单地使用下面的代码来做到这一点。
ImageView imageView = findViewById(R.id.header_image);
Glide.with(this).load(R.drawable.header_image).into(imageView);
ImageView imageView2 = findViewById(R.id.header_image);
Glide.with(this).load(R.drawable.header_image).into(imageView2);
Run Code Online (Sandbox Code Playgroud)
但这需要将同一张图像两次加载到内存中,由于内存问题我不希望这样做。我只想一次加载该图像并将其显示为两个图像视图,我该怎么办?
我正在尝试使用 Android Commit Content API制作图像键盘。为了实现这一点,我需要能够在设备上存储.png文件.gif并从中创建文件对象。
目前,我正在使用 Glide 库从互联网上获取图像。我可能获取的示例图像是这样的。Glide 库为我提供了drawables包含动画 GIF 的库。我需要能够将这些可绘制对象编码为.gif可以在用户手机上保存为文件的文件。
我怎样才能做到这一点?
我查看了现有的帖子,例如:How to conversion a Drawable to a Bitmap? ,但它们没有帮助,因为该Bitmap对象无法存储动画 GIF。
这篇文章:将 gif 文件从可绘制文件保存到手机 SD 中?并在使用后将其从 SD 中删除似乎也相关,但是,它没有解释如何将动画Drawable对象转换为对象列表Bitmap。
此外,它没有解释如何将一系列Bitmap对象保存为 1 个 GIF 文件。
我注意到我必须在Kotlin项目中使用kapt而不是annotationProcessor使其Dagger 2正常工作。我是否必须对所有库(特别是Glide和Room)执行相同的操作?
我想使用Glide加载具有动态高度的图像。我有一个ImageView,其高度为wrap_content,宽度为match_parent。回收器视图首次加载时。第一幅图像的高度大于其余图像的高度。当我向下滚动视图进行回收时,我的较大高度的图像可以很好地加载且没有任何像素化;当我滚动回到顶部的第一张较大图像时,它得到了像素化的感觉。由于图像变得像素化。我不想在recyclerview上使用setRecyclable(false)。这是实现
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/drc_imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@color/OFF_WHITE" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
用于加载图像
GlideApp
.with(context)
.asBitmap()
.fitCenter()
.load(absoluteHomeList.get(position - 1).getDynamic_card_url())
.into(holder.dynamicImageView);
Run Code Online (Sandbox Code Playgroud)
我已经使用Glide下载图片很长时间了,所以这样的代码比比皆是:
GlideApp.with(getContext())
.load(imgUrl)
.into(imgView);
Run Code Online (Sandbox Code Playgroud)
突然我需要记录每个图像的网址以进行进一步分析。而不是搜索 Glade 的每个用法并像这样更改代码:
GlideApp.with(getContext())
.load(imgUrl)
.listener(requestListener) // log urls through listener
.into(imgAd);
Run Code Online (Sandbox Code Playgroud)
有什么方法可以像 Glide 的默认选项一样全局添加 requestListener ,这样我就不需要搜索和更改整个应用程序中的每个 Glide 用法?
我使用 Glide v4,并且检查了将 url 直接记录到 logcat 但不记录到本地存储以进行进一步分析的帖子。
我想创建一个小的动画微调器然后我的图片正在加载。但是出了点问题,或者我可能是瞎子,不明白我应该改变什么。第一个问题是当占位符“加载”时 ViewHolder 很大。
第二个问题是微调器不旋转。如果有人能告诉我我错在哪里,我会很高兴。
XML:
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="720">
<shape
android:shape="ring"
android:thickness="2dp"
android:useLevel="false">
<gradient
android:angle="0"
android:endColor="@color/cesar_blue_69cff7"
android:startColor="@android:color/transparent"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>
<androidx.cardview.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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="50dp"
android:layout_marginTop="10dp"
app:cardCornerRadius="10dp"
app:cardElevation="2dp">
<ImageView
android:id="@+id/storeItemImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
tools:src="@drawable/enter_2_car" />
<TextView
android:id="@+id/storeItemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="12sp"
tools:text="someText" />
</androidx.cardview.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
爪哇:
with(containerView) {
GlideApp.with(containerView)
.load("https://i.picsum.photos/id/688/5000/5000.jpg")
.override(290, 78)
.centerCrop()
.placeholder(R.drawable.progress_circle)
.into(storeItemImage)
}
Run Code Online (Sandbox Code Playgroud)
图片:

是一个问答游戏,答案可以是文本或图像,我正在使用 Gilde 图像来加载它,但对于某些用户而言,即使互联网良好且图像质量低,图像也无法加载。
我将复制所有代码,因为我不知道是否是 Gilde 问题。
if (AppConstant.arQuestionList.get(questionid).getArAnswer().get(i).getAtype()
.equalsIgnoreCase("image")) {
txtOption = new ImageView(this);
try {
Glide.with(QuestionActivity.this).load(AppConstant.arQuestionList.get(questionid)
.getArAnswer().get(i).getAnswer()).override(60, 60).into((ImageView)
txtOption);
}catch (OutOfMemoryError e){
e.printStackTrace();
}
txtOption.setPadding(5, 5, 5, 5);
} else {
txtOption = new TextView(this);
((TextView) txtOption).setText(AppConstant.arQuestionList.get(questionid)
.getArAnswer().get
(i).getAnswer());
((TextView) txtOption).setTextColor(getResources().getColor(R.color.answer_color));
((TextView) txtOption).setTypeface(tf, Typeface.BOLD);
((TextView) txtOption).setGravity(Gravity.CENTER);
txtOption.setPadding(10, 20, 10, 20);
}
Run Code Online (Sandbox Code Playgroud)
布局
<LinearLayout
android:id="@+id/answerwrap"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_30"
android:layout_marginRight="@dimen/dp_30"
android:layout_marginTop="@dimen/dp_30"
android:orientation="vertical">
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 以前没有发生在我身上,我正在努力弄清楚。
我正在尝试在RecyclerView. 图像每次都应该是随机的,我使用以下服务:https://picsum.photos/200/200/?random
但是,当我加载应用程序时,它RecyclerView会一遍又一遍地显示相同的图像。
为了清楚起见,我清除了持有人:
Glide.with(context).clear(holder.view.avatar)
holder.view.image.setImageDrawable(null)
Run Code Online (Sandbox Code Playgroud)
然后加载它
Glide.with(context)
.load("https://picsum.photos/200/200/?random")
.into(holder.view.avatar)
Run Code Online (Sandbox Code Playgroud)
知道会有什么问题吗?
我RecyclerView在每一行里面都有一个 和 ,我ImageView用它Glide来从 URL 设置图像。问题是当我第一次打开并尝试滚动RecyclerView时,只会下载图像。显然它会保存到缓存中,下次就不会再次下载。
我希望第一次预加载图像,这样当用户滚动时他/她就不必等待。
请看代码:
@Override
public void onBindViewHolder(PostAdapter.MyViewHolder holder, int position) {
try {
Post post = postArrayList.get(position);
if (checkNull(post.getDesc())) {
setText(holder.postDesc, postArrayList.get(position).getDesc());
} else if (checkNull(post.getUrl())) {
setImage(holder.postImage, postArrayList.get(position).getUrl());
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void setImage(ImageView image1, String str) {
image1.setVisibility(View.VISIBLE);
Glide.with(context).load(str).
diskCacheStrategy(DiskCacheStrategy.ALL)
.into(image1);
}
Run Code Online (Sandbox Code Playgroud)