How to stop the animation of GIF Image in Recyclerview in android - java

I had to use GIF image in RecyclerView.In first position GIF is playing. then i moving to the next items.then previous GIF image will should be stop. How to solve this task.

use the getDrawable()method to get the GifDrawable object and call the stop() method:
((GifDrawable)buttonGifImage.getDrawable()).stop()
or since you have setup as background resource:
buttonGifImage.setBackgroundResource(R.drawable.gifImage);
use: ((GifDrawable)buttonGifImage.getBackground()).stop()

Related

ImageView background change while .animate() [Java][Android Studio]

I'm trying to do some 'nice' animation during rotation of the image.
I mean, I'm trying to change image bacground while the rotation reach 90f (is totally invisible), to continue rotation with other src.
In this test case, I'm trying to rotate chest image and end the animation with coin image.
rC1 is obviously an ImageView
rC1.animate().setDuration(500).rotationYBy(90f).withEndAction(new Runnable() {
#Override
public void run() {
rC1.setBackgroundResource(R.drawable.coinb);
rC1.animate().setDuration(500).rotationYBy(90f);
}
});
And well, it works, because the animation starts, then ending with invisible chest 90f and then it appears with both images - chest and coin like this:
https://ibb.co/48W2Xjh
animation: https://i.ibb.co/pftWYwz/315774853-505872868270345-6007333826531395103-n.gif
I checked all other functions etc. to check if anything can overwrite it, but none connects with it.
An ImageView can both have a source image and a background image. I am guessing you are adding a background image and not changing the source image or vice versa. Try changing rC1.setBackgroundResource(R.drawable.coinb); to rC1.setImageResource(R.drawable.coinb);

ImageView onClick animation doesn't work after change in resource

I'm new to android, and I am currently working on a simple connect three game, I have nine ImageViews which contain transparent images, when the ImageView is clicked, the resource is changed to x or o.
I've tried adding more animation, and setting resource to null rather than a transparent image, but it didn't work, only restarting the activity seems to fix it.
public void oneClick (View view)
{
//image view onClick
ImageView one = (ImageView) findViewById(R.id.one);
one.setImageResource(R.drawable.x); //setting x or y
one.animate().rotation(180).setDuration(500); //animation
}
Here's how I reset the images,
one.setImageResource(R.drawable.transp)
After this, if the onClick activity is called again, the image is set.
However the animation doesn't seem to work.
What am I doing wrong?
My image was rotated 180, so it wasn't rotating again, the simple solution was to reset the orentation of the image then run the rotate animation again, which seems to have fixed it!
clicked.setImageResource(R.drawable.x);
clicked.animate().rotation(180).setDuration(500);
after this
clicked.animate().rotation(0);
now if I use the rotation animation again, it seems to work!
This is a simple fix. Simply add .start() to your animation. It should look like this afterward:
one.animate().rotation(180).setDuration(500).start();

ExoPlayer switching media source without black screen

I'm using exoplayer in my project, when switching mediasource i just use
player.stop();
player.prepare(mediaSource);
This causes approx. 0.5 seconds black screen until it switches video.
Is there a way to tell exoplayer to retain last frame from previous video (instead of 0.5 sec black screen) until new video is started?
simpleExoPlayerView.setShutterBackgroundColor(Color.TRANSPARENT);
Exoplayer's developers have provided solution to this issue here.
Simply add this line using your SimplePlayerView instance
playerView.setKeepContentOnPlayerReset(true);
Alternatively, you can also do this via your layout.xml file,
app:keep_content_on_player_reset="true"
In my case I'm having a single instance on SimpleExoPlayer and i used to set this via setPlayer in exoplayer view with changed video url's but having blank screen when scroll back to previously played videos.
I just used setPlayer(null) before again setting the player in exoplayerview and the black screen issue fixed.

Android GIF transparent background disappears

I'm new to Android Java programming. For a project I need transparent images, which change dynamically. I have created a layout with an ImageView. And in it a small GIF USA flag GIF with a transparent background.
In code I connect the variable to the imageview and assign the same image to the variable from the ImageResources
ImageView image = (ImageView)convertView.findViewById(R.id.listview_image);
image.setImageResource(R.drawable.vlag);
This goes pretty well however the image is displayed with a white background. The transparency is lost. This is shown in the image below by the white background.
GIF over ImageView are always an issue. Use GIFImageView
And you must use it this way:
gifImageView = (GifImageView) findViewById(R.id.gifImageView);
gifImageView.setBytes(bytes);
gifImageView.startAnimation();
Even it has an option to download the gif from the web.

SurfaceView is displaying camera feed sideways

For some reason the camera feed in my program is sideways. If I hold my finger up to the camera from the bottom, it shows up as coming from the right in the surfaceview.
I have a pretty standard implementation
surfaceView = (SurfaceView)findViewById(R.id.surfaceView);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(surfaceCallback);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
I've looked around but I can't seem to find any information on this. My device is a nexus One.
EDIT: If I set the screen orientation to landscape then it works fine for some reason... Can't get it in portrait though.
The orientation of the preview display image is controlled by Camera.setDisplayOrientation(int) method. For my Evo, setting the orientation to 90 makes the preview display correct for portrait mode.
...
camera.setParameters(parameters);
camera.setDisplayOrientation((orientation+90)%360);
camera.startPreview();
...
It seems that changing the orientation after the preview is started causes an exception. If you change rotate the phone/device, the SurfaceHolder.surfaceChanged callback will be called again, if you do the setDisplayOrientation and startPreview in that callback, you get an exception. I'm, going to try stopping preview, then changing the orientation then starting it again.
Note: There is also the Camera.Parameters.setRotation(int) method, that (I think) changes the orientation of the image when it is written into the (JPEG) output image when a picture is taken. This method does not change the preview display orientation.
use this line
mCamera.setDisplayOrientation(90);
in surfaceCreated method after
mCarmera.open();

Categories

Resources