Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Fit image to full width using Picasso library

Tags:

android

I am using Picasso library to load images and its working fine but after using this library image is not fit to the layout. If I set image directly to the ImageView then image will be fit to the layout .Is there any option to pass method in Picasso to fit image to layout

Picasso.with(getContext())
                    .load(R.drawable.dddd).
                    .into(lavdateimageView);

Even I tried to call following method but no use

fit(),croptinside() etc

XML file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none"
        android:background="#ffffff"
        >


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:background="#ffffff"
            >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="260dp"
                android:layout_marginBottom="3dp"
                android:id="@+id/lavdate_image"
                android:orientation="vertical"

                >
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"

                    android:id="@+id/lavdateimageView" />
            </LinearLayout>
            <TextView

                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="New Text to"
                android:padding="3dp"
                android:background="#ffffff"
                android:textColor="#000000"
                android:layout_margin="3dp"
                android:textStyle="bold"
                android:id="@+id/sss"  />

        </LinearLayout>
    </ScrollView>



</LinearLayout>
like image 453
Vision Coderz Avatar asked Nov 05 '16 15:11

Vision Coderz


People also ask

How do you fit a picture on a Picasso Android?

There are two things to know about fit() . First, calling fit() can delay the image request since Picasso will need to wait until the size of the ImageView can be measured. Second, you only can use fit() with an ImageView as the target (we'll look at other targets later).


2 Answers

<ImageView
    android:id="@+id/image"
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"/>

myPicassoProvider.get(activity).load(getImageUrl()).into(image);

In this way your image will be as width as you want and will keep aspect ratio

like image 138
Krzysztof Dziuba Avatar answered Jan 01 '23 09:01

Krzysztof Dziuba


I had also same problem so I tried this it works fine

Picasso.get()
       .load(IMAGE_URL)
       .fit()
       .centerCrop()
       .into(imageView);
like image 44
Hanzala Avatar answered Jan 01 '23 09:01

Hanzala