Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trespass ViewGroup's Limits when using animations

I have a ImageView inside a RelativeLayout. The ImageView is filling the whole RelativeLayout. The RelativeLayout cannot become bigger.

I want to make the ImageView bigger using ScaleAnimation like that:

final ScaleAnimation scaleAnimationGoBigger = new ScaleAnimation(1, 1.5f, 1, 1.5f,        Animation.RELATIVE_TO_SELF, (float)0.5, Animation.RELATIVE_TO_SELF, (float)0.5);
scaleAnimationGoBigger.setDuration(1000);
scaleAnimationGoBigger.setFillAfter(true);
myImageView.startAnimation(scaleAnimationGoBigger);

The RelativeLayout's boudaries do not allow the whole new bigger ImageView to be shown, showing only the parts that fits the RelativeLayout (making it to looks like a zoom effect).

So my question is: is there a way to tell a View inside a ViewGroup to not obey (to trespass) the ViewGroup's boundaries where it lies in (at least during the animation) ?

like image 337
Dragons_Lair5 Avatar asked Dec 05 '25 19:12

Dragons_Lair5


1 Answers

is there a way to tell a View inside a ViewGroup to not obey (to trespass) the ViewGroup's boundaries where it lies in ....

Yes. Lets say you have a View (myImageView) inside some ViewGroup (viewGroupParent). Just called setClipChildren(false)

    ViewGroup viewGroupParent = (ViewGroup) myImageView.getParent();
    viewGroupParent.setClipChildren(false);

More info here : http://developer.android.com/reference/android/view/ViewGroup.html#attr_android:clipChildren

(at least during the animation) ?

Use Animation.AnimationListener, altogether, it should look something like this:

final ViewGroup viewGroupParent = (ViewGroup) myImageView.getParent();
viewGroupParent.setClipChildren(false);

final ScaleAnimation scaleAnimationGoBigger = new ScaleAnimation(1, 1.5f, 1, 1.5f,        Animation.RELATIVE_TO_SELF, (float)0.5, Animation.RELATIVE_TO_SELF, (float)0.5);
scaleAnimationGoBigger.setDuration(1000);
scaleAnimationGoBigger.setFillAfter(true);
scaleAnimationGoBigger.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            viewGroupParent.setClipChildren(false);
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // uncomment here if you want to restore clip : viewGroupParent.setClipChildren(true);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // do nothing
        }
    });
myImageView.startAnimation(scaleAnimationGoBigger);

HTHS!

like image 195
petey Avatar answered Dec 09 '25 19:12

petey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!