Android - picasso shows only placeholder, not the

2019-02-24 00:07发布

问题:

I've got this code

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ImageView image_view = (ImageView)findViewById(R.id.imageView1);

        Picasso.with(getApplicationContext()).load("http://nuclearpixel.com/content/icons/2010-02-09_stellar_icons_from_space_from_2005/earth_128.png").placeholder(R.drawable.ic_launcher).noFade().into(image_view);
    }

And i want to view the image from url in my imageview... however instead of the image only the placeholder shows. What may be the problem?

回答1:

Try using just picasso.load() instead of Picasso.with()

Something like this:

Picasso.Builder builder = new Picasso.Builder(getApplicationContext());
Picasso picasso = builder.build();
picasso.load("http://nuclearpixel.com/content/icons/2010-02-09_stellar_icons_from_space_from_2005/earth_128.png").placeholder(R.drawable.ic_launcher).noFade().into(image_view);