Is it possible to change the alpha value of an ImageView along a specific direction i.e. from top to bottom or bottom to top on Android?
I am trying to animate with imageView.animate().alpha(0).setDuration(500).start();
however this just fades the entire view out uniformly, but I'd like to do this form top to bottom instead.
Any help appreciated.
As far as I know, it is not (yet) possible with the Android built in animations. You will have to create your own custom animation.
Haven't tried, but maybe you can achieve this by using the Transformation class, and/or overriding the onApplyTransformation method from the AlphaAnimation class
method.
Related
I'm new to Android programming. I'm working on an app that requires some form of animation. Please take a look at
I want an animation where a scroll rolls down at the top with this text in it as soon as this activity starts & rolls up when the connect button is pressed. I have no clue where or how to begin with the animation. Any kind of links to tutorials or posts on StackOverflow will be of much help.
Thank you for your time!
Since your question is really really broad, I'll give you a broad answer as well.
I think by "scrolling animation" you mean an animation in which a black (or some other color) area slowly covers up/reveals the screen. I don't know why would this look cool, but whatever.
Step 1
Create an animation XML file. In this file, you would specify that the view should translate downwards by x pixels where x is the height of the screen. And create another animation file. This time, specify that it should translate upwards.
If you need help creating XML view animations, have a look here
Now you have two animations - move upwards and downwards.
Step 2
Okay, now you should create a custom view. You can start by doing this:
public class ScrollingView extends View {
}
And implement all the required constructors.
Override onDraw like this:
cover the whole view with black or some other color
draw the scroll at the top of the view. The scroll should be an image like this one:
If you don't like using an image, you can draw it yourself, using code!
You can get help on this here
Step 3
In onCreate of your activity, create a ScrollingView. This view should be as wide as the screen and as high as the screen. Position the view at (0, 0) and bring it to front so that it covers up the whole screen.
Step 4
Next, apply the animation you created in step 1 to the scrolling view.
What I want to achieve is this
sample
basically there must be 2 layers where the one on top needs to have a hole on a specific location, with a specifc radius, that can show the underneath layout. Moreover, the hole can must be able to be resized (scale animation).
The best thing I've found is a proper library (https://github.com/amlcurran/ShowcaseView) but looks limited and I don't want to import a library just for that. Another solution could be to add a custom shape and add it as a background to the top Layout (the problem with that solution is that I am not able to move the shape and to set the position/size). Or I could have a canvas and draw over it but looks overkill.
Is there an easier component to I use in order to achieve this result?
I am experimenting with Views in Android and am trying to create a custom 'widget'. What I want to do is create a portion of a circle with an indicator at 12'o clock. I'd then like to to swipe over the circle and when I do, I'd like to see the indicator move to left or right corresponding to a swipe to the left or the right.
I have looked up a number of sources however I am unsure of how to draw an 'indicator' within the arc. In addtion, what needs to be done to animate the arc ? Can this be achieved without OpenGL ?
I am aware of the circlular progress bar and I believe the problem is quite similar, however I didn't have to add a marker inside the circle.
Here is an image of the screen shot of the View I would like to recreate:
This approach would work,Creating a View with rounded corners and position it to bottom to make it seem like arc
Is it possible to rotate views in XML with APIs previous to Honeycomb - maybe with the support package? Or is the only way to create a custom class, like described here Vertical (rotated) label in Android
Edit: What I need is a statically rotated view (specifically a TextView, but I guess it's enough to know how to do it with a View). Starting with honeycomb there's a rotation attribute which can be used in XML. I need something like that.
The only thing I have found until now is use an animation with duration 0 but this still moves a bit at start and I don't want that. I tried setting the views invisible and attaching a listener to the animation which makes them visible on animation finished callback, but that made strange results... that changed the position of the views, for some reason.
The best way is with the custom subclass implementation that you linked to, where you can rotate the canvas and resize the view appropriately. This ensures that the view bounds are also set to match the text that is drawn.
The only method of transforming views externally prior to HC is the animation framework, and applying an Animation to the view with a duration of 0 and fillAfter set to true will work, but you may notice flickering on some devices as often the view will render normally on its first frame and then animated to its final position from that point onward. You can work around this by hiding the view and displaying it a bit late...but you can see how hacks are starting to stack up.
In addition, doing an Animation prior to HC will not transform the view bounds themselves, so you won't be able to neatly pack other views around this one because its position from a layout perspective will still be the rectangle calculated for the horizontal (non-rotated) text.
The simple subclass is definitely the preferred method.
HTH
Is it possible to rotate views in XML with APIs previous to Honeycomb
There is RotateAnimation. However, depending on what you are trying to accomplish, that may not meet your needs.
I'm working on a game that in some ways is similar to Tetris (imagine a 2D array of colored squares that sometimes move around)
I am trying to animate the individual squares so they will smoothly slide down from coordinate to the next. Since I wanted to use Android's built-in tweening feature, the animation has to apply to the whole View (rather than parts of it). This doesn't work well for me because I only want some of the colored squares to slide down, and the rest of them to stay still.
The (theoretical) solution I came up with to resolve this is to make 2 Views, layered directly on top of each other. The top view is for animating squares when they need to move, and the bottom layer is for the static squares. The animation-layer is transparent until I am ready to animate something. I then simply turn on the colored square in the animation-layer, tween it to the new location, and turn it back off when done. In the same time span, the static-layer just turns squares on and off at the right time to make the whole thing look seamless to the end user.
The proposed solution is just a theory, since I haven't been able to make it work correctly yet. Since I have been having trouble, I was wondering if this is even the best way to solve the problem? Perhaps there is a more elegant solution that I am over looking? Anyone know of a better way?
If you just want to animate a single element check out the namespace android.view.animation.Animation. You can also use Drawable shapes and draw them directly. Finally, if you want a simulation then you will have to look into threading. Basically you will create a timer to update the canvas for you based on an interval. There are some other view canvases you can use as well like the GLView canvas.