How to create a "reveal" effect that's not circular? - android

Android has a nice reveal animation (called "CircularReveal") that has a circle shape (link here and here) .
I was wondering: is it possible to do it in other shapes too?
For example, reveal a view from top to bottom, in a rectangle shape, as such:
XXX XXX XXX
... => XXX => XXX
... ... XXX
A video of how it looks like can be found here.
In the previous way to do it, I've used a customized ObjectAnimator (link here) that changes the layout params (which works, but it's a workaround and it's not quite customizable, and it will probably not work on this case), but I wonder if there's a new way to do it, something easier and more customizable.
Also, is it possible to make this kind of animation work on previous Android versions, and not just Lollipop?
It's just that I've seen "Google Now Launcher"'s search-history appear this way, and I wonder how to make a similar thing.

You could create a New Animator like this http://cogitolearning.co.uk/?p=1451 and define your own rectangular animator. Here is a reference link to the GitHub source code posted by the author.

The Google Now search history animation just looks like a simple translate to me. It looks like the top search bar is in front of the history drop down. By animating the views in front (of your view you want to be revealed) to go down, I think you would get the reveal you are looking for. See: https://stackoverflow.com/a/19766034/2832027

The only solution I've come up with is to put a view as a second layer (on top of the listView) that is identical to the background, which has a scaled down animation.
so it's like that in the layout XML:
<FrameLayout >
<ListView/>
<View/>
</FrameLayout>
This should work, but it's more of a workaround.
Also, it has some disadvantages:
another layer means more overdraw.
might be tricky in case you have a complex background.
it's probably not as nice to use as a real reveal-animation.

Check my project: https://github.com/mageRabbitStudios/coolandroidstuff/tree/master/MyCircularReveal_12_3_19
In there you can create any reveal animations you wish. It will sound complicated but is quite simple. I created custom ImageView where I access the "clipPath" property of its canvas.(The only way I found to change the clip mask of a view, there is simpler solution shown on the third ImageView where I access only clipBounds property of the ImageView and during that it is not neccessary to create custom view) I update the clipPath on every draw which is called only during the animation's execution using AnimatorUpdateListener and using ObjectAnimators and custom Evaluator I manage to create from circle to rectangle reveal animation :)
Convert it to Java if you don't understand Kotlin

Related

Android Studio does not show anchor points when laying out a custom component in a ConstraintLayout

I've developed a super simple custom View in Android, to be used as a generic placeholder, that just shows a diagonal line between the upper-left vertex to the lower-right one.
The problem is that when I try to lay out it in a ConstraintLayout, the editor does not show the anchor point I would expect. An image is worth a thousand words:
If you're experienced with Android Studio you know that if I were using a standard View, like a Button, instead of mine custom View, the green arrow should normally hook to the grey "BUTTON", representing a vertical constraint.
Any idea why Android Studio does not behave as expected ?
It is an Android Studio bug or maybe my custom view misses something else like some callback method ?
It is worth to mention than if I manually edit the layout XML writing the proper contraints and then I reopen the view, it is shown correctly, with all the arrows representing contraints in place! Even the one that I was not able to draw in the first place.
Ok, the answer was quite easy. In order to properly work, it is mandatory to assign an android:id to all components. If some components involved in a ConstraintLayout do not have it, it is impossible for Android Studio to set such constraint. This is because a constraint has this kind of form:
app:layout_constraintTop_toBottomOf="<ID OF THE COMPONENT ATTACHED TO>"
So... in my case it was enough to ensure all components, be them custom or default ones, have an ID.

How to create flip animation in android?

I have a tablelayout with multiple viewFlipper in each square. What I want is whichever viewflipper i touch, the view should flip. Everything is working fine but what I need is this kind of animation.
The animator files given there cannot be used in viewFlipper.setInAnimation(this, android.R.anim.fade_in);. We need to use anim for it not animator.
Android do give some built in animations but all of them are fade, slide etc but not flip. I think flipping is one of the most used animations, why isn't android providing one in default or am I missing something ?
You can try github library - Flip 3D View.
Finally I was able to solve this. Although there is a library but you need not used the whole library just for flipping views. check out this tutorial. Basically you create an animator xml as shown in the android guide in question. Then you can use it to animate any object not only views. Just use it like this
Animator flipAnimator = AnimatorInflater.loadAnimator(this,R.animator.card_flip_left_in);
flipAnimator.setTarget(cardView);
flipAnimator.start();

Android - animating views in xml

I searching for a way to animate views via xml, I am really lost in this part of UI programming.
Can anybody explain to me step by step how to do this?
You can animate android views by using Animation resources.
With xml animations you can set different properties e.g duration, rate of change (interpolator).
AndroidHive has a very good tutorial with a nice set of animations
http://www.androidhive.info/2013/06/android-working-with-xml-animations/
From my experience with xml animations, you won't know what you want until you've played around with different properties.
http://developer.android.com/guide/topics/resources/animation-resource.html
Update:
Interpolators as well are also important,they allow you to achieve a lot more smoothness. But misusing them can also be expensive so be make sure its necessary.
http://developer.android.com/reference/android/view/animation/Interpolator.html
This blog also gives a quick peek into the actual effects of interpolators:
http://android-er.blogspot.co.uk/2012/02/various-effect-of-interpolator-in.html

Android - How to create a shake effect like delete in iphone?

I have gridView which has lot of images and on clicking the edit button, I want the images to wobble just like : how to create iphone's wobbling icon effect?. Appreciate any pointers to solve this issue.
You can start off by modeling the wobble effect as a combination of Animations that Android provides. You can then extend an ImageView and use an AnimationSet of this combination of Animations.
You can create an xml that defines how the ImageView will be animated, load the animation in code referencing this xml and then apply it. A brief documentation here.

Animating Picture Transitions

I'm starting out with Android development, and I'm kind of stuck. Basically, I have a layout with dynamically added ImageViews, and I want to have the ImageViews change their image every once in a while. However, I'd like to add some sort of transition or changing animation, like a flip or a flash.
I don't really know where to even start to look for an answer to this question. Any help is greatly appreciated.
The android framework has this totally covered:
http://developer.android.com/guide/topics/graphics/view-animation.html
Basically, you are looking to define "tween" animations between your drawables (imageviews). After you define your animations you can even define a set of drawables to show one after the other using frame-animation.
Check out the following for all the gory details:
http://developer.android.com/guide/topics/resources/animation-resource.html

Categories

Resources