I am using Universal Image Loader in my app.
It is the best libary to download images, but I have one problem.
I download images that they are smaller than width of device.
I need the image have width = device width and scaled height.
Any idea how I can do this?
you can use imageview like this
<ImageView
android:id="#+id/imageView_clock"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="#drawable/ic_icon" />
and its depends on your image size from web
android:scaleType="centerCrop" // use this
Related
I am working with an application in which I have more work with images. I want to show profile pictures and Article images in my app. For article images I have tried scale type of ImageView to "fitcenter or centercrop or fitxy" but nothing works fine. My image pixel's are distorted. I am using Glide library to show image on sever. I have even tried .fitcenter() etc. Glide methods but nothing works so that my image work fine with ImageView.
Code:
<ImageView
android:id="#+id/imgArticle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/blank_image" />
Glide Code:
Glide.with(context).load(articleList.get("article_image"))
.thumbnail(0.5f)
.placeholder(context.getResources().getDrawable(R.drawable.blank_image))
.fitCenter()
.into(imgBanner);
I have tried various methods i.e. fitcenter, centercrop etc. but nothing works.
android:scaleType="fitXY" will stretch your image. You can try this code so that image will not stretch.
<ImageView
android:id="#+id/imgArticle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/blank_image" />
Or you can adjust the height and width as per your UI
<ImageView
android:id="#+id/imgArticle"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/blank_image" />
<ImageView
android:id="#+id/bigimages"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_below="#+id/productTitle"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="40dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="#drawable/bath_and_body_1" />
Glide.with(this)
.load("https://images-eu.ssl-images-amazon.com/images/I/41ZNY84Q-7L.jpg")
.placeholder(R.drawable.cancel_icon)
.into(bigimages);
https://images-eu.ssl-images-amazon.com/images/I/41ZNY84Q-7L.jpg
this is my code and image URl i have to display full image without streching but i am not able to display its stretched please suggest me how to fix it . below is current image which is stretched
enter image description here
how to fix there is stretching in text yellow....
YOu can try :
android:scaleType="fitXY"
android:adjustViewBounds="true"
Change to
android:scaleType="centerCrop"
or
Glide.with(this)
.load("https://images-eu.ssl-images-amazon.com/images/I/41ZNY84Q-7L.jpg")
.placeholder(R.drawable.cancel_icon)
.centerCrop()
.into(bigimages);
Of the various scaleType options, fitXY is specifically made to stretch the image. It will make sure that the entire image is stretched/shrunk to fit in exactly the space provided.
You probably want centerInside; this will make sure that the entire image fits within the view, and will not distort the aspect ratio. If your view is square and the image is rectangular, centerInside will scale the image down so that it fits inside the view, meaning either the top+bottom or left+right will be empty.
Alter your Glide implementation with:
Glide.with(this)
.load("https://images-eu.ssl-images-amazon.com/images/I/41ZNY84Q-7L.jpg")
.override(width, height) //set width & height as you want
.palceholder(R.drawable.cancel_icon)
.into(bigimages);
References:
Glide Image Resizing & Scaling
Glide Documentation
I have confusion for the loading of the bitmap into android device screen or any digital device for example LED TV screen here my android mobile screen resolution like 768x1280 pixels and I want to load bitmap resolution like 3000x2000 pixels here may be two type of possibility arise first one directly load bitmap without and resizing of the original bitmap second one form original bitmap to take the resizable bitmap and load into device screen but question arise into the first case how to load larger bitmap into small device screen can anybody help me for this confusion.
For reference consider this image :
Here this image have resolution 3000x2000 pixels and mobile screen resolution 768x1280 pixels.
Use "picasso" plugin:
picasso page
Example:
Picasso.with(context).load("link or #drawable/...").into(imageView);
You can add .fit() and image will fill imageView.
Picasso.with(context)
.load("link or #drawable/...")
.fit()
.into(imageView);
Rotate image to 90 degree(either outside or inside XML), Then Fit with scaleType attribute.
Firstly either you can add rotated image to your resource or rotate it with XML attribute, like this.
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rotation="90"
android:src="#mipmap/your_image" />
Then, Scale it with scaleType attributes (fitCenter, centerInside or centerCrop)
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rotation="90"
android:scaleType="fitCenter"
android:src="#mipmap/your_image" />
Note: If you only give scaleType to your ImageView without rotation then your image will be stretched.
Hey everyone I have been running into an issue with Picasso. I am trying to load an image from sound cloud but it keeps appearing stretched or very small. Here is my XML
<ImageView
android:id="#+id/album_cover_art"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/fragment_content_item_top_margin"
android:scaleType="centerInside"
android:contentDescription="#string/content_description_image_placeholder"
android:src="#drawable/placeholder" />
I tried to use picasso's resize and center inside but the image appears small.
Picasso.with(getContext()).load(mSelectedTrack.getArtworkURL()).resize(800,300).centerInside().into(mAlbumCoverArt);
Using picasso's resize and center crop maintains the image view size but leads to the image appearing stretched.
Picasso.with(getContext()).load(mSelectedTrack.getArtworkURL()).resize(800,300).centerCrop().into(mAlbumCoverArt);
Any ideas on a way to do this that is easier than writing a function to resize it myself ?
I avoided image stretching using :
.resize(800,0)
Passing 0 as second parameter it preserved the image proportions.
Hope it helps
try this:
for your imageview:
<ImageView
android:id="#id/img"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true" //add this
android:scaleType="fitCenter" />
And in picasso use .fit().centerCrop()
Picasso.with(getContext()).load(mSelectedTrack.getArtworkURL()).resize(800,300).fit().centerCrop().into(mAlbumCoverArt);
Try setting height or width to fixed and other to wrap content and load Picasso with .fitXY and don't use . resize.
Give a try to Glide.
https://github.com/bumptech/glide
Glide.with(this)
.load(imageUrl)
.centerCrop()
.override(300, 300)
.into(imageView);
I try to display 3 images medium size.
The problem is that they display in low quality and it damages the UI a lot,I checked over the internet and the best solution is to use is Piccaso,but I want to know how can I display the image in it's full quality without third-library?
I load images like this:
<ImageView
android:id="#+id/btnring"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/itayring1"
/>
and I also tried this:
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.itayicon);
b1.setImageBitmap(bb);
When I used Eclipse I could load images easly. There must be a way to do in Android Studio too,
Thanks.
Put Images in xhdpi drawable image only and try this code :
<ImageView
android:id="#+id/btnring"
android:layout_height="50dp"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:src="#drawable/itayring1"
/>