Material Layout Animation

One of the ideas of Android L is that the popup should start from where the user tapped the screen.
For example, in Chrome Beta (@time * 5):
Chrome Beta

The idea is to be able to enlarge the view from any pivot point (not just to the predefined position of the overflow button) Has anyone done this or is not feasible at the moment?

+6
source share
2 answers

There seems to be no clean way to do this.
The only viable option I found is to write 4 different xml animations (for 4 corners, more if you want to allow centering), all ScaleAnimations from 0 to 1, with different pivots for each (4 corners )

Then use DialogFragment :

 @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Dialog dialog = super.onCreateDialog(savedInstanceState); dialog.getWindow().getAttributes().windowAnimations = R.style.downRightCornerAnimation; //instead of referring to R.*, call a method to get the specific //resource you need for a given start position return dialog; } 

And one example of such an animation:

 <?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator" android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0" android:toYScale="1.0" android:fillAfter="false" android:duration="200" android:pivotX = "0%" android:pivotY = "100%"/> 

This is very cumbersome and hacked, but I donโ€™t think the SDK gives us the best tool for this (AFAIK you cannot just enter a dynamic ObjectAnimator in DialogFragment or PopupWindow )

+1
source

Well, I think animation in general should work for you.

To do this, run the following code:

 RecyclerView view = (RecyclerView) findViewById(R.id.your_view); Animation appear = AnimationUtils.loadAnimation(this, R.anim.appear); apear.startAnimation(view); 

Then, inside your res / anim folder (create it if it isn't), create an xml file called manifest.xml and place the following code:

 <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:android:fromXScale="0" android:toXScale="1.0" android:fromYScale="0" android:toYScale="1.0" android:duration="1000" /> </set> 

Change the values โ€‹โ€‹for your purposes.

You can get more information from the Android Animation developers and see the animation API.

0
source

Source: https://habr.com/ru/post/973591/


All Articles