How to animate a "cloned", recurring version of an existing Android view

I have an ImageView that is on the ViewPager page, and suppose I would like to animate it to scale + move it somewhere off the screen, while the original view is still present in the pager, intact .

What is the best way to create this type of animation on Android 4.0.3+? I would like to use the new animation structure, not the old one.

One of the ways I decided is to use DecorView activity: create an ImageView clone there and make an animation, but I feel it's a bit of a hack - the decor looks more like a hidden function and implementation detail.

Is there a better way?

+6
source share
1 answer

I think you can get DecorView using DecorView by setting setClipChildren() to false for all ImageView parents. This allows you to animate the View from your layout, even outside its parent (and even Activity ). I mainly use a helper method:

 public static void setClipView(View view, boolean clip) { if (view != null) { ViewParent parent = view.getParent(); if(parent instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view.getParent(); viewGroup.setClipChildren(clip); setClipView(viewGroup, clip); } } } 

Therefore, simply use this method on an ImageView as follows:

 LayoutHelper.setClipView(imageView, false); 

To animate the View itself, you must use the new animation API introduced with Android 3.0 (Honeycomb - API Level 11).

This DevBytes video is also related to this. It processes custom Activity animations and duplicates an ImageView to animate the transition from one Activity to another. This is basically the same thing you are trying to do, just in two different Activities .

+2
source

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


All Articles