Is there a way to show a gif inside a SurfaceView? - java

I created a surfaceVeiw with a custom Background and a little figure. So far so good. Is there a posibility to show a Explosion (not as one picture but as a little video) when the figure collides with objects?
I already created these objects so the only thing I need to know is, how I can implement a method to show such explosion.
Do you need some code to help me?

You can use glide libray for showing gif in android
Glide.with(context)
.load(imageUrl)
.asGif()
.placeholder(R.drawable.loading_gif)
.into(imageView);

Related

I'm trying to get the image srouce of an ImageView

I'm doing a card matching game at the moment and I am fairly new to Android studio so forgive me if this is a stupid question. I'm at the point where i am trying to compare two image views to see if they have the same image source.
While i'm able to do this to set the image source
ImageView obImg = findViewById(R.id.ivCard2);
obImg.setImageResource(R.drawable.AceS);
After searching around for a while i'm not sure how to get that image resource
//there's nothing simple like
obImg.getImageResource;
//and this seems to crash my program
obImg.getTag();
Thanks for everyone's help in advance

How can I prevent an ImageView from resizing to fit the screen programmatically?

I am making a 2D platformer type game. I made a ImageView using JAVA, that Is supposed to be about twice the size of the screen horizontally.
However, when the ImageView is displayed no matter the size of the Image, it keeps re-sizing to fit my screen . Note that I am not using XML, but I am purely using JAVA. How can I prevent this?
Here is the code:
ConstraintLayout gameLayout;
gameLayout = findViewById(R.id.gameLayout);
ImageView map = new ImageView(this);
map.setImageResource(R.drawable.tutorial_map);
map.setX(0);
map.setY(0);
gameLayout.addView(map);
Feel free to edit further if necessary.
Use map.setScaleType(ScaleType.FIT_XY);
or
You can also use map.setAdjustViewBounds(true);
Make sure you use map.setBackgroundResource(R.drawable.tutorial_map) instead of map.setImageResource(R.drawable.tutorial_map).
What framework are you using to build the game. My suggestion would be to use libgdx which is super lightweight, cross platform and awesome. Trust me this question will be the least of your problems. As a developer, you need to think of how your code is going to change tomorrow.
So, since you are using an imageview, just set as fixed the width of your window and scale your imageview as you wish. Cheers!

Android gif animation with ImageView

I have a .gif file with four frames, i used Ion library for animation but it doesn't show good result. Because this library shows previous frame along with animation. How can i fix that?
Here is a link to a relevant question Display Animated GIF that has already been answered. Essentially, it says that you can display .gifs with the android.graphics.Movie class. It has been available from API level 1. check out this code linked here https://code.google.com/p/apidemos/source/browse/trunk/ApiDemos/src/com/example/android/apis/graphics/BitmapDecode.java#103
and from line 103 down there is an implementation of it opening an gif resource

Camera overlay in Android

So without a screenshot you guys won't know what I'm talking about.. So here we go:
This particular part of my application I need to do an overlay over the camera interface as seen in the screenshot. 2 rectangles - And when you take the picture, I want to end up with 2 images, the cuttings taken from the 2 rectangles.
If this doesn't make sense, please comment and ask for clarification. I honestly don't even know where to begin with this one. What would be a good starting point? Is this even possible?
I guess you will have to create your own Custom Camera:
http://developer.android.com/guide/topics/media/camera.html#custom-camera
where you can implement your own preview layout - thus you can put those frames over camera preview as you wish
but it won't be easy as many of devices exists with many different camera resolutions, some work only in landscape, even though their native interface is portrait, it's a fake landscape; and also aligning those frames with the picture you'll be actually getting will be a challenge; but definitely this is Custom Camera - good luck

Image Importing & Painting in Android Java

Recently, I have taken java and now am heading into Android Java.
However, Android has quite a few different things to tackle when programming.
So as my title says, how can I Import an image from my /res folder and paint it on the screen?
Usually, I would do something like this.
import java.awt.*
And in main class
public Image img;
And in public void paint
case CASE:
g2d.drawimage(...)
break
This doesn't seem to work in android.
Can someone explain how you could import and display images in a location in android?
It's great to see someone new trying out android development.
As for your question you could use and ImageView though if you are looking for something more dynamic then you should use a canvas. It will allowing for drawing images and animations.
I highly recommend you check out these tutorials:
Here is a list of 200 android tutorials that really helped me start out. Though some go over features that are now deprecated.
Android Tutorials
Here is where the videos start going over basic game making. It goes from video #61 to about #80.
Android Tutorial #61
These videos can help you draw a basic image or make a simple game if that's what your looking for. Though I recommend you go learn as much of the basics as you can before going into anything really complicated.
Don't overextend yourself with something to difficult to begin with because it migh leave your frustrated with the entire android concept.
Hope this helps.
u can add images/picture in the res/drawables
http://developer.android.com/guide/topics/graphics/2d-graphics.html
Also different devices use different resolutions
http://developer.android.com/guide/practices/screens_support.html
use a ImageView widget to display the image
image = (ImageView) findViewById(R.id.imageView1);
image.setImageResource(R.drawable.android);
this is assuming you have a file name android.png|jpg|gif etc in your drawable folder. If you want to use a image that is selected at runtime check here. How to set the image from drawable dynamically in android?

Categories