3

我在RelativeLayout中有一个ImageView。 ImageView正在填充整个RelativeLayout。 RelativeLayout不能变大。使用动画时Trespass ViewGroup的限制

我要让使用ScaleAnimation的ImageView的更大的那样:

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

的RelativeLayout的的学边界不允许显示整个新的更大的ImageView,只显示适合的RelativeLayout部分(使得人们看起来像一个缩放效果)。

所以我的问题是:有没有办法告诉一个ViewGroup内的视图不遵守(以非法访问)ViewGroup的边界位置(至少在动画期间)?

+0

同样的问题。 ;( – Gavjr 2014-09-04 15:06:43

回答

1

有没有办法告诉ViewGroup中内的一个视图不服从(以 侵入)的ViewGroup中的边界的地方在于....

是。假设您在某个ViewGroup(viewGroupParent)中有一个View(myImageView)。刚才打电话setClipChildren(false)

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

此处了解详情:http://developer.android.com/reference/android/view/ViewGroup.html#attr_android:clipChildren

(在动画至少)?

使用Animation.AnimationListener,干脆,就应该是这个样子:

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!

+0

谢谢,这解决了我的问题,但如果有一个解决方案,我可以告诉视图不遵守其父视图组边界,而是告诉父母允许视图这样做,这主要是因为可能会有更多而不是一个viewGroup,它会剪切我的视图,强制我将“setClipChildren(false)”放到每个viewGroup中,以剪切我的视图。 – 2014-09-05 13:02:03

+0

Android给出了这种开箱即用的方式。是你说的方式,但是你想要循环这个操作,然后在你创建的静态util类中,这是相当容易的。另一种方法是创建视图的副本并将其放入PopUpWindow类的实现中,可以放弃编写这个实用程序和循环,但这将是另一个问题的答案;-)最好的运气和最好的。 – petey 2014-09-05 13:40:28