Android - ImageView does not display image. Nor does setImageResource() - android

I use an ImageView control as shown:
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/imgHangMan"
android:src="#drawable/hang0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
The above code displays the image in the Graphical Layout preview of the xml file. But on launching the app, I see no image. Also, changing the image using
imgHangMan = (ImageView)findViewById(R.id.imgHangMan);
imgHangMan.setImageResource(R.drawable.hang1);
This piece of code also does not work either. The image files are in .gif format and are in the drawable folder.
Any pointers ?

Natively ImageView doesnot support animated image. You have two options to show animated gif file
1) Use VideoView 2) Use ImageView. But Split the gif file into several parts and then apply animation to it.
Try this link-playing-gif-animation you will get the desired result.

Try this
image.setImageDrawable(getResources().getDrawable(R.drawable.hang1));

User this :
http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
Go by this.

Related

Image not showing in android studio emulator

i don't know what is the problem with my android studio i am trying to add an image from image view ..it is showing in design tab but not in emulator ...i am a newbie ..please help me fix it ..thanksAndroid Studio
i tried fixing it by changing the attributes but didnt work ..
You are setting a sample_image to an imageView. To set an image, give it a real source.
android:src="#drawable/any_image"
give source of an image drawable
Download any jpg or png image from google and paste that image in drawable folder than add this line in to you imageview widget -> android:src="#drawable/TestImage"
like this->
<ImageView
android:id="#+id/imageview"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="#drawable/TestImage">

Image in drawable won't show up in Resources section when choosing resource in 'src'

I am trying to set a background image for my app. I have the image in the Drawable section.
I have created an ImageView and am trying to set the src to that file.
However, the image doesn't show up anywhere in the Resources window that opens.
I also tried setting the image as src manually through the XML. But then the image won't display.
The name of the image satisfies all conventions (all lowercase characters, no special characters, etc).
I've used images before but I can't wrap my head around this particular case.
XML code:
<ImageView
android:id="#+id/backgroundImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:src="#drawable/weatherbackground" />
I'm not setting the image through Java code.
Any help would be greatly appreciated.
Thanks.

Showing a gif with transparent background in an ImageView

I have a coloured gif image that I would like to use in my application, I imported the image into my application by dropping and dragging the gif into res/drawable.
However the transparent background turns white when it is shown in an imageview, here is my code
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:scaleType="fitXY"
android:src="#drawable/logo"/>
How can I make android show the transparent background and not a white one?
Thanks
I think its better to open a gif in a webview. you can put the gif file in a html file and open it in webview. also you can set your app background in html file to make your work easier.

How can zoom image with multiple Touch in android?

I am going to create image gallery. How can i zoom image using multiple touch. i got pinch-0.8 library but how can i use it. if you have any other idea then help me.
Zoom effect with ImageView in android.
There is a library available at Image Zoom
Download two files
ImageViewTouch.java
ImageViewTouchBase.java
To use image view inside your layout file, write following code
<com.package_name.ImageViewTouch
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="#drawable/image" />
NoTe
Make sure, you have put those files inside any package, like com.customview or something like that. So that you can refer that in layout file.
Link
You can download sample from sephiroth/ImageViewZoom

Why android resizes image?

I'm trying to change my application data source to the sdcard so that it doesn't take too much internal memory.
However, I had an Image that was dynamically loaded from the resource and displayed in an ImageView, now I load the image from the sdcard whenever I need it.
I had been using imageBox.setImageResource(imageID) and I changed to imageBox.setImageDrawable(imageDrawable).
The problem is that now Android resizes my image and it doesn't fit where it should.
Why is it resizing the image this way? And how can I stop it?
Thanks in advance :)
Add the tag android:scaleType="fitXY" to your ImageView's layout XML.
Ex.
<ImageView
... several settings ...
android:scaleType="fitXY"/>
Edit:
If your image is simply too big to fit inside the ImageView - it will have to do some kind of scaling. There are some other options as described in the API:
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
Try the following for ImageView:
android:layout_height="fill_parent"
android:layout_width="fill_parent"
No Scale Type.
The ImageView Should be within Fixed Size (in dp) Parent View.

Categories

Resources