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

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);

Related

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

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()

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();

Sprite Cropping LibDGX

I've been trying to draw an image of a block with an eye on the screen. I want to be able to animate more than one texture in the same way, so drawing the animations by hand is not an option. The problem is that when I move the eyelid sprite higher up than completely closed, part of the eyelid shows above the expected bounds like this. Obviously, this is a problem as it looks quite unnatural. I'd like to either have an alternative solution to this problem, or be able to crop the eyelid's Sprite object to fit behind the rest of the image. The final image consists of the eyeball, pupil (as I want to be able to animate this too), eyelid, main body and the outlines, drawn in that order. The render function looks like this:
public void render(float delta) {
float height = this.eyelid.getHeight();
float eyeHeight = height*0.7f;
this.eyelid.setY(this.eye.getY()+(eyeHeight*((100-this.lid)/100f)));
batch.begin();
this.eye.draw(batch);
this.pupil.draw(batch);
this.eyelid.draw(batch);
this.main.draw(batch);
this.shade.draw(batch);
batch.end();
}
this.lid is the % of how closed the eye is, and the image for the eyelid itself can be found here. How could I solve this problem, or how could I crop the sprite? I don't want to have to reload the texture as a sprite every frame.
I think what you're looking for is the ScissorStack class, which is documented on the libGDX wiki. You can use this object to clip around the eye's frame so that the top of the lid doesn't show.

Stop background from resizing itself

So in my application, I'm using the system wallpaper as the background.
I'm doing so with the following code -
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getActivity());
Drawable wallpaperDrawable = wallpaperManager.getDrawable();
view.setBackground(wallpaperDrawable);
The problem is, the background is trying to squish inwards. In other words the system image is trying to fit the whole image in one bit and it looks weird. How can I stop the background from resizing itself?
More info, on my homescreen, the wallpaper would be a picture of a car, you can only see the front part of the car. But when you open my app, you can see the full car but its squished and resized.
How can I go about doing this?
Perhaps this would help (from the WallpaperManager Class page):
wallpaperManager.suggestDesiredDimensions(int minimumWidth, int minimumHeight);

ObjectAnimator Choppy Scrolling

I have an activity that contains a HorizontalScrollView. The HorizontalScrollView has three fragments in it. On a button click the scrollview will scroll from left to right or vice versa. I am accomplishing this like so...
private void scrollTo(int x) {
ObjectAnimator animator = ObjectAnimator.ofInt(mScroller, "scrollX", x);
animator.setDuration(800);
animator.start();
}
On my Nexus 7 (1st Gen) it scrolls smoothly, but on my Moto G phone, it is super choppy. Any ideas how I could correct this?
Update
I figured out that if I changed the background drawable on one of the fragments the problem will go away. The image I was using is very plain, so I never thought that would be the problem. The image I replaced it with is much larger in size, but is just a repeated pattern.
I set the background with a .png like this
android:background="#drawable/my_background"
Old Background (non working)
New Background (works)
It ended up being my background image. I used a 9 patch tool located here to generate different size images and all is well now.
http://android-ui-utils.googlecode.com/hg/asset-studio/dist/nine-patches.html

Categories

Resources