Fixed Size ImageView Shows Images in different sizes - android

I am working on an application where i have to download images from server, at server i have images of different form. like jpeg,png.
I am using volley to download my image
<com.android.volley.toolbox.NetworkImageView
android:layout_marginLeft="5dp"
android:layout_width="65dp"
android:layout_height="65dp"
android:id="#+id/main_profile_image"
android:layout_gravity="center_vertical"
android:scaleType="fitCenter"
android:background="#eeeeee"
android:layout_centerInParent="true" />
but my outcome comes in form
Screen Shot
How to fix it. Any Help?

try this it will help
android:scaleType="centerInside"
android:adjustViewBounds="true"
becuase scaleType="fitCenter" is by default when you omit
see this

Related

How to show original size of the image without it being stretched in Android?

Sorry for the my English, Actually the problem is that i get the images through json in android but when i show it in full size the image got stretched can you please tell me what to do??
this is my xml file
<ImageView
android:id="#+id/portFullImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="115dp"
android:layout_marginLeft="18dp"
android:layout_marginRight="22dp"
android:layout_marginTop="70dp"
android:src="#drawable/logo" />
maybe you can try with scaleType in your ImageView
<ImageView
android:scaleType="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/logo" />
You have specified top and bottom margins by using android:layout_marginTop="70dp" and android:layout_marginBottom="115dp" which are very big amount of space if device is small in my opinion. it will make your ImageView already small.
If you don't bother about it, try android:scaleType="centerInside" and see if it helps. You may try other scaletypes mentioned in below reference document and check the results.
Reference:
Various ScaleType of ImageView , ScaleType

Blurred profile picture in Android app

I am displaying the Google plus profile picture of the user of my app, but the image is blurred.unless i reduce the size which then makes it almost impossible to recognize who ever is in it.Is there a way to fix this.I am getting the image from a Url.
This is my ImageView
<ImageView
android:id="#+id/profilePicture"
android:layout_width="200dp"
android:layout_height="200dp"
android:contentDescription="hello"
android:maxHeight="200dp"
android:maxWidth="200dp" />
Try display image following way,
<ImageView
android:id="#+id/profilePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="hello"
android:maxHeight="200dp"
android:maxWidth="200dp" />

What is a correct way to place image over ImageView?

I'm novice in android development and still can't understand fully how sizing works with different layouts. I want to place a preview of the book into this template:
I've tried to implement it using FrameLayout. The idea is that the center of preview image will be exactly where the center of the png background is. Here is the code:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/book_frame" />
<ImageView
android:id="#+id/previewImage"
android:layout_width="83dp"
android:layout_height="83dp"
android:layout_gravity="center_vertical|center_horizontal"
android:src="#drawable/abs__ab_bottom_solid_dark_holo" />
</FrameLayout>
The result in layout builder look exactly like I want it to be:
On real phone it is different:
I think on other resolutions it will also differ from both variants. So my question is how to synchronize these images so after any resizing and distortions the preview will fit the cover correctly?
Possible solution would be to remove border from image and place it on previewImage instead. But there are several similar usecases in application where the border can't be removed, so I'd like to find out a universal solution for all of them.
You have your answer in your question.
What happening in your case image size matter for different screen resolution.
Hard-coded things always gives weird result in your case
android:layout_width="83dp"
android:layout_height="83dp" this piece of code.
Check this link this will guide you to manage drawables for different screens.
and here is another link
So the suitable solution for me was to separate border of inner image into its own ImageView, insert it into layout over the photo and add 1dp padding to the photo.
The layout become like this:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5" >
<ImageView
android:id="#+id/bookFrame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:src="#drawable/book_frame" />
<ImageView
android:id="#+id/previewImage"
android:layout_width="83dp"
android:layout_height="83dp"
android:layout_gravity="center_vertical|center_horizontal"
android:padding="1dp"
android:scaleType="centerCrop"
android:src="#drawable/abs__ab_bottom_solid_dark_holo" />
<ImageView
android:id="#+id/previewBorder"
android:layout_width="83dp"
android:layout_height="83dp"
android:layout_gravity="center_vertical|center_horizontal"
android:src="#drawable/preview_border" />
</FrameLayout>

How do you properly scale ImageView

ALL,
I am developing an application on Android where I need to load an image from the web and present it to the user in a ListView along with some other stuff. So I made 2 XML files (for row and whole display), wrote code to get the image and wrote the appropriate adapter.
Here is what I have:
product_line.xml:
<ImageView
android:id="#+id/product_picture"
android:contentDescription="#string/product_picture"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/product_name"
android:layout_toRightOf="#id/product_picture"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/product_price"
android:layout_below="#id/product_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/add_to_cart"
android:layout_below="#id/product_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add_to_cart"
/>
Unfortunately, upon running the code I see that the view is much bigger than the downloaded image and so takes a lot of spaces despite the "wrap_content" settings.
Is it possible to somehow set the view dimensions to display everything properly?
Thank you.
[EDIT]
I found this: http://argillander.wordpress.com/2011/11/24/scale-image-into-imageview-then-resize-imageview-to-match-the-image/, but unfortunately it doesn't make any differences.
[/EDIT]
To scale down your image view use:
android:adjustViewBounds="true"
android:maxWidth="32dp" <!--set the width you wish to be -->

Overlapping image not properly displayed on all formats

I'm building a graph which consists of 2 images: 1 background image and one image containing the actual data points. The data points image show be aligned at the top of the background image.
The layout looks like this:
<RelativeLayout
android:id="#+id/graphImageWrap"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/graphImageBackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#android:color/transparent"
android:contentDescription="#string/stroom_grafiek"
/>
<ImageView
android:id="#+id/graphImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/graphImageBackground"
android:layout_centerHorizontal="true"
android:background="#android:color/transparent"
android:contentDescription="#string/stroom_grafiek"
/>
</RelativeLayout>
This works well on a HDPI device:
But on a MDPI device it doesn't align properly:
I hope someone can explain what the problem is.
You may want to use a FrameLayout instead, and make sure the images are the same size.

Categories

Resources