In wirelessly often encounter the need to choose a thing, such as choosing a date, select a file, choose a location, etc., usually we do is to use the selection dialog, such as the choice of date with DatePicker, sometimes also use activity, but both of these ways have a disadvantage, Is that the user is obviously feeling the switch between the interface. Sometimes, this choice of data should be better interactive:
In fact, the above app effect comes from the app with Capitainetrain, it seems to be a train app, and the app's author also introduced this effect in his blog, while opening up the source to achieve this effect. This article is written on the basis of the author's blog post.
I did not directly translate, because the idea is more complex, I did not understand the author's meaning, I read the text below a lot of comments also said that they did not understand the meaning of the author, estimated that the author itself is not clearly elaborated. After I have implemented a demo based on the author's source code, I write some understanding of myself. At the end of the article I will post the original address and the code download address.
In the picture above, the date selection screen will be displayed gradually after the selection of the button "Select Date", while the "Select Date button" will slowly move to the top position, and "Select the Date button" The following section slowly moves down and has a low opacity until it disappears. When the animation ends, only the "Select Date button" and the date selection screen are left. The whole process is like all the elements in the interface are given a certain set of rules to give the space to the forthcoming interface, over very natural, and the different positions of the selection control triggered by the upper and lower translation animation is different (such as when the control itself at the top, the control will not move up the animation effect), very flexible, Users in the two interface switching process, the idea is closely linked.
Perhaps only the foreign developers will be so careful.
Finish the effect, we will look at the source structure:
Formanimatordemoactivity.java is an example of a demo I added myself, because the author's own example looks dazzling.
Mainwithanimatoractivity and Mainwithoutanimatoractivity are two ways to implement this effect: Property Animation and general gradient animation mode. The gradient animation works very well, but his specific code helps us to understand the logic of implementation.
Customanimator is a custom animation class that is the core code for property animation implementations.
Positions encapsulates the properties of a few columns of different objects.
Positiontypeevaluator is a custom estimation method for property animations, which is a reference to the use of property animations.
Using property animations requires only the following three lines of code:
Animator.setanimatorviews (Mmaincontainer, Localfrom, Mfirstgroup, Arrays.aslist (New View[]{msecondgroup, Mfirstspacer,mthirdgroup}), NULL, Meditmodecontainer, arrays.aslist (New view[]{})); Animator.prepareanimation (); Animator.sta RT ();
Where animator is defined as follows:
|
private CustomAnimator animator =newCustomAnimator(); |
The hardest thing to understand here isanimator.setAnimatorViews的7个参数,没明白这7个参数的意思,既无法知道如何调用,也无法去研究CustomAnimator的源码。
我们来看CustomAnimator中setAnimatorViews的定义:
public void Setanimatorviews (ViewGroup maincontainer, view focusedview, view Focusedviewcontainer, list<view> Fadedouttobottomviews, View Stickyto, ViewGroup Editmodeview, list<view> slidetotop)
mainContainer:整个布局的最上层容器。
focusedView: The control that is clicked, which is the selection control mentioned above.
focusedViewContainer: focusedView the parent container where it resides.
fadedOutToBottomViews: The view list that disappears to the bottom of the animation process
stickyTo: I don't know what to do.
editModeView: The selected interface is hidden.
slideToTop: The view list is slid to the top in the animation process.
What I want to say here is that at the level of API design, the author is poorly designed. However, this is also the most economical code, and the author has a lot of skills in handling property animations.
Among them, mainContainer ,focusedView、focusedViewContainer、editModeView四个参数是必须的。但是fadedOutToBottomViews以及slideToTop如果同时为空效果将大打折扣。实际上fadedOutToBottomViews和slideToTop列表里面具体需要哪些view完全取决与开发者自己根据当前UI的情况判断。我的理解就到此为止了,并没有深入的去研究代码。
Original address: http://www.cyrilmottier.com/2014/05/20/custom-animations-with-fragments/
最后是源码,作者在自己的demo中并没有完全实现上面gif图片中的效果,而是做了个简单的能说明使用方法的demo,个人觉得这个demo做的不好,作者demo的在:
https://git.mika-dev.com/Mika/custom-animations-with-fragment
In order to see the effect more visually, I modeled the GIF layout and made a demo of myself.
http://download.csdn.net/detail/jianghejie123/8102407
The realization of natural over-effect of selecting control and selecting Interface in Android--a new interactive design