Vision Coderz
Vision Coderz

Reputation: 8078

Android Fit image to full width using Picasso library

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>

Upvotes: 13

Views: 14008

Answers (4)

Vision Coderz
Vision Coderz

Reputation: 8078

Finally I understood my mistake. I used android:scaleType="centerCrop" and now my image is fit to layout

  <ImageView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:scaleType="centerCrop"
      android:id="@+id/myimageView" />

Upvotes: 13

Hanzala
Hanzala

Reputation: 1983

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

Picasso.get()
       .load(IMAGE_URL)
       .fit()
       .centerCrop()
       .into(imageView);

Upvotes: 17

Krzysztof Dziuba
Krzysztof Dziuba

Reputation: 591

<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

Upvotes: 1

Mithun Sarker
Mithun Sarker

Reputation: 4023

Try changing the property of your imageview like this

<ImageView 
                android:id="@+id/lavdateimageView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"
            />

And then

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

Upvotes: 1

Related Questions