ImageView onClick animation doesn't work after change in resource - java

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

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

JavaFX Capture Screen without ImageView in it

I'm trying to take a screenshot with Robot and view it in an ImageView, The problem is the screenshot coordinates is the ImageView Global coordinates.
So basically I'm trying to capture what's behind the Imageview but instead I get a picture of the Imageview itself.
I can't minimize because I'm taking several continuous screenshots that may vary in resolution.
What can I do?

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

Android how to apply flip rotation animation on each element of grid view?

i have a grid view and i want to apply flip rotation animation on every child of grid view.
when user touch on a grid view element it perform flip rotation animation and change image.
and i use table layout to create grid of images.
i want to perform like thisPlz check once
this performs on one(layout).
but i want to perform on a 48 elements.
any help from someone....
plz give suggestion soon..
thanks in advance....
One of the most convincing 3D flip animation I've seen is done here https://code.google.com/p/android-3d-flip-view-transition.
A lot of the other tutorials and sample codes don't produce believable 3D flips. A simple rotation on the y-axis isn't what's done in iOS.
There is also a video here: http://youtu.be/52mXHqX9f3Y
So, to flip each grid element, simple call:
ViewFlipper viewFlipper = getViewFlipperForItem(i);
AnimationFactory.flipTransition(viewFlipper, FlipDirection.LEFT_RIGHT);
Where getViewFlipperForItem is a method you implement to get the ViewFlipper on that cell. I suggest you add each cell as a ViewFlipper (or ViewAnimator) and add the images you intend to flip within the ViewFlipper (or ViewAnimator). If this isn't clear to you, let me know.
Use the below code for adding flip animation to a view in android.
final ObjectAnimator animation = ObjectAnimator.ofFloat(view, "rotationY", 0.0f, 360f);
animation.setDuration(3000);
animation.setRepeatCount(ObjectAnimator.INFINITE);
animation.setInterpolator(new AccelerateDecelerateInterpolator());
animation.start();
view.startAnimation(animation);
Thanks Ephraim,
I used view flipper in my project and used that library that you have mentioned. It looks great and it help me out. Please any one who want to animate his view like rotate should use this library.
https://code.google.com/p/android-3d-flip-view-transition.

Can an View play its animation out of its parent?

I have some ImageViews in a TableLayout's TableRow. When I start an animation of one ImageView using the following code:
ImageView image = (ImageView)findViewById(id);
TranslateAnimation a = new TranslateAnimation(0, 0, 0, 80);
a.setDuration(500);
image.startAnimation(a);
the image is expected to move downwards. But unfortunately it's in a TableRow, so I can see the image moves "in the backstage of the row". Any ideas? I can't use other layouts because of a lot of existing codes.
The answer is no. Animations change properties of an view, but can't take it out of its parent. At last I gave up and use another layout.

Categories

Resources