square / picasso

A powerful image downloading and caching library for Android
https://square.github.io/picasso/
Apache License 2.0
18.72k stars 3.97k forks source link

Using placeholder makes images appear tiny #106

Closed timothyjc closed 11 years ago

timothyjc commented 11 years ago

Using a gridview with a custom adapter. The first time I load the GridView the images are all squashed into a single pixel or something as per the screenshot:

Picasso.with(mContext).load(url).placeholder(R.drawable.stub).into(view);

device-2013-06-29-201523

The second time I load up the activity it looks ok:

device-2013-06-29-201545

If I do not specify a placeholder it does not crush up the images but it does have the wrong image while it loads...

dnkoutso commented 11 years ago

Can you please provide a url and your layout for the gridview? I'd like to test it and fix this.

timothyjc commented 11 years ago

Here is the first page of urls:

[http://ns3002439.ovh.net/thumbs/rozne/thumb-2867822.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2871091.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2869131.jpg, http://ns3002439.ovh.net/thumbs/manga-anime/thumb-2874629.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2867430.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2866472.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2871296.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2867585.jpg, http://ns3002439.ovh.net/thumbs/manga-anime/thumb-2874624.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2867680.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2869287.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2870969.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2866133.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-359539.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2880058.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2862286.jpg, http://ns3002439.ovh.net/thumbs/manga-anime/thumb-2871144.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2878364.jpg, http://ns3002439.ovh.net/thumbs/high-resolution/thumb-2867500.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2865787.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2867839.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2871093.jpg, http://ns3002439.ovh.net/thumbs/manga-anime/thumb-2865285.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2858957.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2872090.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2865719.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2866534.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2869565.jpg, http://ns3002439.ovh.net/thumbs/manga-anime/thumb-2874630.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2855297.jpg, http://ns3002439.ovh.net/thumbs/manga-anime/thumb-2874625.jpg, http://ns3002439.ovh.net/thumbs/rozne/thumb-2866908.jpg]

ImageAdapter:

package com.citc.wallbase.utils;

import java.util.ArrayList; import java.util.List;

import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView;

import com.citc.wallbase.R; import com.squareup.picasso.Picasso;

public class ImageAdapter extends BaseAdapter {

private List<String> urls = new ArrayList<String>();

private Context mContext;

public ImageAdapter(Context c) {
    mContext = c;
}

public int getCount() {
    return urls.size();
}

public String getItem(int position) {
    return urls.get(position);
}

public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView view = (ImageView) convertView;
    if (view == null) {
        view = new ImageView(mContext);
    }
    String url = getItem(position);
    Picasso.with(mContext).load(url).placeholder(R.drawable.stub).into(view);
    return view;
}

public void setUrls(List<String> urls) {
    this.urls = urls;
}

public void addUrls(List<String> urls) {
    this.urls.addAll(urls);
}

public void clear() {
    urls.clear();
}

}

I also tried with inflating the following grid item like this but it didn't help: <?xml version="1.0" encoding="utf-8"?> <ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" />

grid.xml

<GridView
    android:id="@+id/gridview"
    android:layout_below="@+id/header"
    android:layout_above="@+id/ad_seperator"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:numColumns="auto_fit"
    android:stretchMode="columnWidth"
    android:columnWidth="230px"
    android:listSelector="#00000000" />
JakeWharton commented 11 years ago

The custom drawable doesn't work well with views that don't define a size. You should try the SquaredImageView from the sample.

timothyjc commented 11 years ago

I tried with the SquaredImageView and it works (but the image size is square).

I subsequently tried with this but it had the original problem:

setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight());

This works for me though: setMeasuredDimension(getMeasuredWidth(), 188);

dnkoutso commented 11 years ago

There is definitely a few issues with PicassoDrawable we will look into it.

demoNo commented 11 years ago

I solved this by

view.setImageResource(R.drawable.stub);
Picasso.with(mContext).load(url).into(view);
dnkoutso commented 11 years ago

Did you try this with Picasso 2.0? Download source and build manually. Official release coming soon.

demoNo commented 11 years ago

I will try later.

dnkoutso commented 11 years ago

Updates on this?

timothyjc commented 11 years ago

It now works without the code I posted above in 2.0... Thanks.