PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 27, 2022

[FIXED] How to fit Image into ImageView using Glide

 July 27, 2022     android, android-glide, android-layout, crop, image     No comments   

Issue

My concern is how to fit image using android:scaleType="fitXY" into image using Glide.

My ImageView is

<ImageView
    android:id="@+id/img_pager"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:scaleType="fitXY" />

Loads image using Glide like this

Glide.with(context).load(url).placeholder(R.drawable.default_image).into(img);

but image is not getting fit into ImageView it show space on image either side as shown in screen I need it fitXY

enter image description here


Solution

You can use centerCrop() or fitCenter() methods:

Glide.with(context)
     .load(url)
     .centerCrop()
     .placeholder(R.drawable.default_image)
     .into(img)

or

Glide.with(context)
     .load(url)
     .fitCenter()
     .placeholder(R.drawable.default_image)
     .into(img)

You can also find more information at: https://futurestud.io/tutorials/glide-image-resizing-scaling



Answered By - ArtKorchagin
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing