3

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) ?

Dragons_Lair5
  • 715
  • 1
  • 5
  • 16

1 Answers1

1

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!

petey
  • 16,914
  • 6
  • 65
  • 97
  • Thanks, that solved my problem, but would be great if there is a solution that i can tell the view to not obey its parent's viewGroup boundaries instead telling the parent to allow the view to do so, mainly because there may be more than one viewGroup that will clip my view, obligating me to put the "setClipChildren(false)" to every viewGroup that will clip my View. – Dragons_Lair5 Sep 05 '14 at 13:02
  • Android gives it to you this way out of the box. I agree it would be nice if it was the way you said but You'd want to loop this operation then in is a static util class you make which is fairly easy enough. Another method, would be create a copy of your view and put it in a PopUpWindow class implementation and you could forgo writing this util and the loop altogether. But that would be an answer to another question. ;-) best of luck and hth's. – petey Sep 05 '14 at 13:40