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.
Related
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.
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.
I need help to place a video at an arbitrary point on a playfield.
I am porting a game which takes place on a playfield - background with animated sprites superimposed. It's working fine.
The activity does a
// Set full screen view
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Off that, I run a View on which all the action takes place. The playfield adjusts in size and offset, depending on screen size and orientation. All that's working fine, and I scale the sprites and their positions accordingly.
But sometimes, I need to place a borderless video on top of an existing background at various specific points in the playfield, and everything I read in stackoverflow is about the video itself and not how to position it. Can anyone help? Where should I start looking?
Ah... It appears that I wanted AbsoluteLayout, which became deprecated in 2009. There is, however, more than one way to skin a cat. I just have to work a bit harder.
I am working in Indoor Positioning System .. It will be an android app like this
I am trying to make custom View for displaying the map, First step I make a Scrollable ImageView following article called 'A simple implementation of a scrollable ImageView'
The problem is when I put a marker in the map (using another ImageView for marker), When I start scrolling .. the markers start disappearing like this
So can any one help me ? I want markers to stick into the map and only the map scroll (I mean like Google Maps)
For creating map, Canvas is a better option, in canvas you can implement scroll,zoom,rotation etc.
In canvas it supports any number of bitmaps, and also we can draw programmatically within the canvas.
I have used SurfaceView in my game. Right Now, I have created layout considering one device (320 x 480). The game layout looks nice and all functions are working properly. But when I see the same game in another device with different dimension (screen size), the layout does not seem to be proper.
So is there any property, method, formula or helping Tutorial by which I can create game design/layout through canvas which looks same in all screen size devices.
There is one simple hint: don't ever use absolute coordinates on the SurfaceView. Every item's position should be calculated at runtime depending on the actual screen size. This way you'll achieve a layout that will look the same way on every device. Hope this helps.