How to transition images within the same image view - java

I am using two ImageViews as a background for my app and its terribly slow so i need to figure a way to transition these images with a fade like transition without using two different ImageViews and simultaneously changing the alpha levels when the button is clicked.
the effect im trying to achieve would be similar to this
img1.setAlpha(0.0f);
img2.setAlpha(1.0f);
img1.animate().alpha(0.1f);
img2.animate().alpha(0.0f)
but i need to achieve an effect similar to this using only a single imageView and changing the image resources.

Related

layout background pattern

I would like to know if it is possible create this in android studio for
layout background of my activity.
Reapet a drawable and move in a direction.
You can try adding this dependency to add gif animation:
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.25'
and use FrameLayout.
As an alternative, consider the using the MotionLayout widget to manage motion and widget animation.
This can be done in many ways:
Animated Vector Drawable as the android:background
Animated Gif
Object Animators
MotionLayout
1
There is many ways to create this.
The most elegant and efficient solution is an an animated vector drawable.
But it is also difficult to get all the information together to do it.
2 This Gif will be big or blurry and a resource hog. but simple to implement
3 ObjectAnimator straightforward create a collect of (about 6)black views , rotate 45 degrees
and use a series of ObjectAnimators to translateX/Y
4 MotionLayout would allow this without code and mostly in studio
Create A Constraint Layout
drag 6 black views, rotate and Position them using the Attributes
Convert to MotionLayout
In the "End" ConstraintSet Modify TranslationX & TranslationY
Set Transition to AutoStart
Create A Transition to AutoJump back to the end.

Are there any ways to modify a JavaFX Image Object?

I'm showing an Image on a Canvas using JavaFX, but I would like the color of certain parts of the image to vary based on a variable. Ordinarily, I imagine this would be accomplished by creating a color mask and adding that to the image, but as far as I can find JavaFX Image doesn't allow any operations like that, and from the documentation it looks like JavaFX Images can only be loaded from a file. I don't want to modify and then reload the file each time the color changes, because that seems pretty inefficient performance-wise.
My goal is to create an interactive offline app in which a small character is shown, and the user can (for example) use an input to change the characters eye/hair color.
Are there any ways to accomplish this? Essentially doing basic image masking/coloration with JavaFX Images and canvases. (Not ImageView)
Thanks for any advice you can give me!

Bitmap (or view?) fading

If I display a bitmap as a background, and then draw 3 other, smaller, bitmaps on top, is there a way to fade the background without affecting the other 3 bitmaps?
Basically what I want to do is to move three 'sprite buttons' and a logo image onto the screen, over the top of the game screen, and have the background fade down while the buttons are displayed. When the buttons move off, I want the background to fade back in again.
Any ideas?
Look, this is a design question initially. I need to see if it's possible before I commit.
I have a background. On this I want to show 3 'sprites'. I want to fade the background down without fading the sprites. Is this possible and, if so, how best should it be done?
Considering that the background image will fade and the other 3 will not, is there a reason why they are in the same "container".
If not, then consider having only the background being altered, and the other three images isolated from the altering code.
If they must be drawned together or inside the same bitmap, consider having regions not to alter inside the bitmap, perhaps by clustering the image, and placing identifiers on those regions with a boolean (such as "isAlterable"), then only calling the fade on isAlterable clusters

Android view with multiple random animation instances

So, I'm working on a main menu activity for my android application.
I want to create background animation where there are things translating from the top of the screen to the bottom. The x position and translation speed of each will be random (within some limits).
I have created a new thread to run this animation (so the UI doesn't get slow or messed up).
I do not want to use a SurfaceView if possible. I'm planning on using an ImageView resource, then using .startAnimation(animation), where animation is a translational animation resource.
My problem:
Is it possible for me to create multiple instances of the same ImageView, if I wanted to run multiple animations at the same time (3 of the same ImageViews falling at different rates and different x positions)?
How do I set the starting point of each of the ImageViews to be at some specific x position? For me to specify an absolute starting point, which type of layout would be required?
Any help is appreciated.
I think I've just decided that a linear layout placed on top of a surface view is the best option. The animation would just be drawn on the surface view while the regular menu interface is contained in the linear layout.
Update:
Used a FrameLayout with a SurfaceView and LinearLayout inside. It works perfectly.

Image that has multi clickable zones/surface/area

I want to have an image on the android screen where different parts of the image can be clickable. What I mean is that, If its an image of 3 circles, I want to be able to click each of these circles,
Then I can add different functionalities to each of these clickable circles.
For an instance in this image below I want to be able to click each distinct color. Is it possible to have on-touch-listener and get you the color ? and can it be an image or has to be drawn in Java OR XML ?
I found a really good widget that helps you make any image muli-clickable. They have some good notes on how to use their widget as well.
The widget has a similar approach as Image mapping in html. The good thing about this widget is that the image can be zoomed and it will not lose the coordinates or areas associated to specific clicks.
Here is the link to their website. the guy who made the widget apparently had similar problem and came up with this widget.
Another solution would have been
creating an ImageView containing the png file referenced
making the whole ImageView clickable
setting an OnTouchListener to the ImageView which overrides the onTouch method
check the colors of the image pixel at the touch position
This is often done with an invisible mask image with one color for each zone (see the popular detailed tutorial), but here the image itself has distinct colors for each zone which makes it more interesting.

Categories

Resources