I'd like to preserve the aspect ratio of an imageView and resize it to fill / fit as large as possible without distorting/changing it's aspect ratio using Picasso.
Thus far I've found this:
which suggests using:
.fit().centerInside()
however when I tried it:
Picasso.with(this).load(boxart)
.fit().centerInside()
.into(imageItem);
Along with my XML:
<RelativeLayout
android:id="@+id/rl_ListView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:layout_gravity="left"
android:layout_weight="0.3" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scaleType="fitXY"
android:layout_gravity="left" />
</RelativeLayout>
However the image still appears distorted (it appears too long and skinny - it's original aspect ratio is distorted) and I am unsure why.
fit()
says that it will "resize the image to fit exactly into the target ImageView", i.e. ignore aspect ratio. – Christopher OrrcenterInside()
should rectify that, i. e. resize the image so that it fits inside theImageView
while keeping the aspect ratio. I suspect that theandroid:scaleType:fitXY
is the problem. – david.miholaImageView
. Or do you want to resize theImageView
, so that it fits the aspect ratio of the image - which in your case would make it a bit wider overall. In that case have a look at this blog post: medium.com/@jpardogo/… -- I originally commented there with some clarifying questions but it seems that when he moved to medium.com all the comments were lost... Ask again if you need more help! – david.mihola