我想在ImagePagerActivity中使用ImageViewZoom和Universal Image Loader.
那么,我做了什么:
在ImagePagerActivity中,我在instantiateItem()函数中更改了一行.我评论了ImageView的位置,并将其替换为ImageViewTouch(4.和5.行)
@Override
public Object instantiateItem(View view, int position) {
final View imageLayout = inflater.inflate(R.layout.item_pager_image, null);
//final ImageView imageView = (ImageView) imageLayout.findViewById(R.id.image);
final ImageViewTouch imageView = (ImageViewTouch) imageLayout.findViewById(R.id.image);
final ProgressBar spinner = (ProgressBar) imageLayout.findViewById(R.id.loading);
final TextView textView = (TextView)imageLayout.findViewById(R.id.text);
imageLoader.displayImage(images[position], imageView, options, new ImageLoadingListener() {
public void onLoadingStarted() {
spinner.setVisibility(View.VISIBLE);
}
public void onLoadingFailed(FailReason failReason) {
String message = null;
switch (failReason) {
case IO_ERROR:
message = "Input/Output error";
break;
case OUT_OF_MEMORY: …Run Code Online (Sandbox Code Playgroud)我正在使用UIL加载远程图像并填充FragmentStatePagerAdapter中的Fragments.我已阅读自述文件和常见错误,但我无法解决这个错误.
这是配置:
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.threadPoolSize(1)
.build();
ImageLoader.getInstance().init(config);
Run Code Online (Sandbox Code Playgroud)
这是我显示我的图像的地方:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ImageLoader imgLoader = ImageLoader.getInstance();
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.loading)
.cacheOnDisc()
.resetViewBeforeLoading()
.bitmapConfig(Bitmap.Config.RGB_565)
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.build();
imgLoader.displayImage(this.contentImage, this.imgView, options);
return layout;
}
Run Code Online (Sandbox Code Playgroud)
这是我在适配器中销毁我的片段的地方:
public void destroyItem(ViewGroup container, int position, Object object) {
if (position >= getCount()) {
container.removeAllViews();
FragmentManager manager = ((Fragment) object).getFragmentManager();
FragmentTransaction trans = manager.beginTransaction();
trans.remove((Fragment) object);
trans.commit();
}
}
Run Code Online (Sandbox Code Playgroud)
最后这是我得到的例外:
{
06-20 12:09:24.877: E/dalvikvm-heap(17043): Out of memory on …Run Code Online (Sandbox Code Playgroud) 我有一个关于https://github.com/nostra13/Android-Universal-Image-Loader库的问题.
我正在使用imageLoader.displayImage(...)将数据库中的图像加载到listview中的imageviews.
文档说这个:
ImageSize targetSize = new ImageSize(120, 80); // result Bitmap will be fit to this size
imageLoader.loadImage(imageUri, targetSize, displayOptions, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
// Do whatever you want with Bitmap
}
});
Run Code Online (Sandbox Code Playgroud)
是否可以为imageLoader.displayImage方法声明目标大小?
我正在尝试使用Universal Image Loader(https://github.com/nostra13/Android-Universal-Image-Loader)在网格视图中显示视频缩略图.我能够让它显示图像缩略图没有问题.
我如何在Application类中初始化UIL:
@Override
public void onCreate() {
super.onCreate();
initUil();
}
private void initUil() {
DisplayImageOptions displayOptions = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.cacheOnDisc(true)
.build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.taskExecutor(ThreadPool.getExecutorService())
.defaultDisplayImageOptions(displayOptions)
.build();
ImageLoader.getInstance().init(config);
}
Run Code Online (Sandbox Code Playgroud)
我如何用它来显示缩略图:
public class MediaCursorAdapter extends SimpleCursorAdapter implements Filterable {
@Override
public void bindView(View rowView, Context context, Cursor cursor) {
String contentUri = getContentUri(cursor);
ImageView imgThumb = (ImageView) rowView.findViewById(R.id.imgThumb);
ImageLoader.getInstance().displayImage(contentUri, imgThumb);
}
}
Run Code Online (Sandbox Code Playgroud)
为简单起见,省略了一些代码.contentUri可以是图像URI或视频URI,在两种情况下都是形式content://...
是否可以使用此库从视频内容URI中显示视频缩略图?怎么样?
我知道这个链接alreday发布这个问题 - Universal-Image-Loader:OutOfMemory Error
但很多图像出现问题OutOfMemoryError我在下面使用
protected ImageLoader imageLoader = ImageLoader.getInstance();
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.aboutlogoicn)
.showImageForEmptyUri(R.drawable.aboutlogoicn)
.showImageOnFail(R.drawable.aboutlogoicn)
.cacheInMemory(true)
.cacheOnDisc(true)
.considerExifParams(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
Run Code Online (Sandbox Code Playgroud)
和ImageConfiguration
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.memoryCache(new WeakMemoryCache())
.denyCacheImageMultipleSizesInMemory()
.discCache(new UnlimitedDiscCache(cacheDir))
.enableLogging()
.build();
Run Code Online (Sandbox Code Playgroud)
出现这种类型的错误
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:546)
Wcom.nostra13.universalimageloader.core.decode.BaseImageDecoder.decodeStream(BaseImageDecoder.java:170)
at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.decode(BaseImageDecoder.java:73)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(LoadAndDisplayImageTask.java:307)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:253)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:128)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
W/System.err(2291): at java.lang.Thread.run(Thread.java:838)
Run Code Online (Sandbox Code Playgroud)
在init displayimage调用之后我使用2以下配置.在我的Android设备缓存内存大小为19Mb如果我加载另一个图像然后显示onLoadingFailed原因是内存不足错误.我使用此链接作为参考 - https://github.com/ nostra13/Android-Universal-Image-Loader 如果有任何解决方案或其他方式plz帮助
我目前正在使用Universal Image Loader 1.9.3并将其初始化为,
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder().displayer(new RoundedBitmapDisplayer(100)).cacheOnDisc().build();
ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(Register.this).defaultDisplayImageOptions(defaultOptions).memoryCache(new WeakMemoryCache());
ImageLoaderConfiguration config = builder.build();
imageLoader2 = ImageLoader.getInstance();
imageLoader2.init(config);
Run Code Online (Sandbox Code Playgroud)
在这里我使用了RoundedBitmapDisplayer,因为我希望图像为圆形,并且我已将xml文件中的图像视图属性设置为android:scaleType ="centerCrop",因此它必须将结果作为中心裁剪图像,但它不会给出中心裁剪图像..图像被拉伸甚至给中心作物....
使用Android Universal Image Loader和 RecyclerView 异步加载图像,我遇到与其他人相同的错误,图像混淆;直到它们全部加载并被缓存。
适配器代码:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.media.Image;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
import com.nostra13.universalimageloader.utils.MemoryCacheUtils;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import romina.theftest.connectivity.ImgDownloader;
/**
* Created by romin on 18/1/2016.
*/
public class ProductRecyclerViewAdapter extends RecyclerView.Adapter {
private List<Product> mValues; …Run Code Online (Sandbox Code Playgroud) android lazy-loading universal-image-loader android-studio android-recyclerview
我在我的Android项目中使用Sergey Tarasevich的库Universal Image Loader将图像加载到ListView中.目前我正在我的适配器中的getView()方法中加载我的图片,一切都按预期工作.
问题是我想提前加载一些图像(三个或四个),以便用户在滚动时不需要等待图像加载.使用Universal Image Loader实现这一目标的最佳方法是什么?
当我尝试使用Universal Image Loader在gridview中设置图像时,我得到了一个nullpointer异常.崩溃发生的同时,第一个图像被下载,并且在应用程序崩溃之前只下载了一个图像.(使用httpscoop查看)
编辑:这是错误的.崩溃发生在第一个图像下载之前,因此它可能会尝试测量不存在的图像.
这是我的网站
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/gridImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/gallery_grid_image_desc"/>
Run Code Online (Sandbox Code Playgroud)
gridview布局只是一个gridview
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/galleryPicturesGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:verticalSpacing="@dimen/gallery_grid_spacing"
android:horizontalSpacing="@dimen/gallery_grid_spacing"
android:numColumns="3" />
Run Code Online (Sandbox Code Playgroud)
我的getView
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
ViewHolder holder = null;
Log.d(TAG, "getView " + position);
if (view == null) {
view = ((Activity) context).getLayoutInflater().inflate(
R.layout.gallery_grid_item, null);
holder = new ViewHolder();
holder.thumb = (ImageView) view.findViewById(R.id.gridImageView);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
} …Run Code Online (Sandbox Code Playgroud) 我正在使用包含图像的ListView.这些图像是从适配器内的Internet加载的.因此我使用的是UniversalImageDownloader.
不幸的是,只要我向下滚动必须下载新内容的地方,ListView的滚动就会"拖延"一段时间.
我实际上期望像ListView滚动的行为非常流畅,但是Image的加载当然可以花费更多的时间 - 这不应该影响滚动的平滑性.
此外,当我向后滚动时,也会出现滞后现象.好像图像没有正确缓存.
也许我的ImageLoader选项设置错误了?
我在适配器上做错了吗?
ListView包含大约20-30张图片,尺寸为640x320(约150kb)
您可以在下面看到我的适配器以及ImageLoader.(Downloader类只是UniversalImageDownloader的包装类)
public class Downloader {
/**
* initializes the imagedownloader with a specific configuration
* I CALL THIS METHOD RIGHT AFTER APP STARTUP
* @param c
*/
public static void initialize(Context c) {
// Create global configuration and initialize ImageLoader with this configuration
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(c)
.threadPoolSize(20)
.threadPriority(Thread.NORM_PRIORITY) // default
.tasksProcessingOrder(QueueProcessingType.FIFO) // default
.memoryCacheSize(20 * 1024 * 1024)
.memoryCacheSizePercentage(15) // default
.discCacheSize(20 * 1024 * 1024)
.discCacheFileCount(100) …Run Code Online (Sandbox Code Playgroud) android lag smooth-scrolling android-listview universal-image-loader