[Android] Picasso, resize() vs resizeDimen()

I had trouble changing my resize() calls to resizeDimen(), having icons displaying in different sizes.

As we can see in Picasso’s RequestCreator class , resize() specifies its size in pixels. So:

MyActivity.java
Picasso.with(this)
.load(a.getLogoUrl())
.resize(
getResources().getInteger(R.integer.header_logo_w), getResources().getInteger(R.integer.header_logo_h)) 
.into(headerLogo);
res/values/integers.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
 <integer name="header_logo_w">96</integer>
 <integer name="header_logo_h">@integer/header_logo_w</integer>
</resources>

Is equivalent to the following resizeDimen() call:

MyActivity.java
Picasso.with(this)
.load(a.getLogoUrl())
.resizeDimen(R.dimen.header_logo_w, R.dimen.header_logo_h)
.into(headerLogo);
res/values/dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="header_logo_h">96px</dimen>
<dimen name="header_logo_w">@dimen/header_logo_h</dimen>
</resources>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s