the picture is stretched in imageview android - android

i want to make animation with two pictures, but they are steretched. When i open this image like src in imageView- all is ok(image 1) , but when i run animation - it steretced(image 2).
<ImageView
android:id="#+id/iv_exercise_info"
android:layout_width="fill_parent"
android:layout_height="238dp"
android:layout_gravity="center" />
I try to set scaleType fitXY, but it does not help me. Sory for my english.

I think layout defined for imageview is where the issue is. Try this.
<ImageView
android:id="#+id/iv_exercise_info"
android:layout_width="wrap_content"
android:layout_height="238dp"
android:layout_gravity="center" />
Hope this solves your issue

Use following :-
android:id="#+id/iv_exercise_info"
android:layout_width="fill_parent"
android:layout_height="238dp"
android:ScaleType="CENTER"

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

How do I use a 9-patch?

I have a 9-patch image and what I want to do is to use it to "seperate" the adMob ad from the app. I want to draw a light blue line exactly where the ad is.
This is the 9-patch:
I added it to layout as ImageView and this is the XML code:
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/adView"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:src="#drawable/ab_transparent_example" />
And this is the result:
But what I want to get is the 9-patch to take the size of the screen, to make a full blue line from left to right of the screen. I've never worked with 9-patch before, what am I doing wrong?
The diagram below is a pretty good visual explanation of what a 9-patch is. As for your specific problem, you should set the 9-patch as the background to the image.
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/adView"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#drawable/ab_transparent_example" />
First you need to know is that 9-patch is image as any other, regarding layout placing it. The difference is in way 9- patch image scale.
In this situation, try to set layout_width to "fill_parrent" or "match_ parent"
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/adView"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:src="#drawable/ab_transparent_example" />

Image is not keep the ratio, how to keep it?

I just created a GUI with only one ImageView. The code below:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/TableLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:background="#drawable/exam_list_bg"
android:gravity="top|center" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/exam_icon_failed" />
</TableRow>
</TableLayout>
Some more info:
- exam_icon_failed.png (97x175)
- i use Galaxy Nexus as preview device (in eclipse)
And the problem:
- In preview screen, i see that the image was OK (keep ratio, no stretch..) But when i install in phone (same screen size with preview device) -> the image was stretched.
Could you give some advice for this case? i want to keep the image ratio. Many thanks!
Add scaleType to your ImageView like so:
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="#drawable/exam_icon_failed" />
Please try this:
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/exam_icon_failed"
android:adjustViewBounds="true"/>
And apply 9-patch to your image if possible. Hope this helps.
change your image view like
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="center"
android:src="#drawable/exam_icon_failed" />
may help you and someone..
Thank for your help.
Finally, i found that it come from my desktop (exactly screen resolution).
When i view the original image with my desktop, it look like a square. I have took a picture from my desktop here: http://i1312.photobucket.com/albums/t530/langhoangal/myQuestions/original_inDesktop_zpsbab06700.jpg
But when i open it by my laptop, i can see it like that (i think you see like that): http://i1312.photobucket.com/albums/t530/langhoangal/myQuestions/original_inLaptop_zpsbf19a22c.jpg -> same with what i can see in my phone.
So, the problem is my computer screen display wrong. :) I have tried to adjust resolution and it ok now, i can see exactly what display on phone.
Many thanks for all of you!
Cheer!

Remove white border around an ImageView

My designer keeps adding a little padding around my image.
I want the image the stick on the top and to fill out the width of the screen.
Here's a screenshot from the designer:
This is my XML code:
<ImageView
android:id="#+id/markertap_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/header_bootsverleih_xhdpi" />
It looks like the image is larger than the screen width, so it's getting scaled down after sizing. Try adding android:adjustViewBounds="true" to your ImageView.
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:id="#+id/imageView"
android:cropToPadding="false"
android:scaleType="fitXY" />
Experienced the same when I used an ImageView for Splashscreen, this^ worked for me.
you might want to add it your image view only this.
It fixed my problem.
android:paddingVertical="0dp"
android:paddingHorizontal="0dp"

show a "loader" in an image view

I know of a couple ways to do this (neither of which I like) - so I'm turning to the experts at SOF.
I want to use the ProgressBar. The catch is that I want to use this as the image/background for my ImageView. Is there a way to do this? I started trying this with drawable but I wasn't sure how to go about it exactly.
You can use a ViewSwitcher to switch between the ImageView and a ProgressBar. You can set the ProgressBar as the first child, and when you are done loading the image, you can switch to the ImageView.
Use FrameAnimation drawable as the source of the ImageView
or you can rotate it use TweenAnimation.
Animation Resource
<LinearLayout
android:orientation="horizontal"
... >
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#android:style/Widget.ProgressBar.Small"
android:layout_marginRight="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/loading" />
</LinearLayout>

Categories

Resources