2013-06-28 65 views
2

我一直在试图找出这个问题的一个很好的解决方案一段时间,但从来没有能够引用它的数字......所以,希望有人可以帮助我或指出我因为我已经用尽了我下一年的Google配额,所以这是正确的方向。Android补间动画修剪边界

基本上,我想要完成的是一个单独视图的ScaleAnimation,当长按时,它将展开,然后收缩以表示它已被按下。

这就是所有设置;那里没有问题。

问题在于ScaleAnimation被视图的父级剪切,并未扩展到其父级。这里的层次:

Relative > 
    Relative > 
     Linear >  (<-- The animation is cut at the outer bounds of this parent) 
      View 

我已经尝试添加机器人:clipChildren =“假”和android:clipPadding =“假”,但既不这些解决方案帮助我居然动画第一父的边界之外。

我知道补间动画设计的目的不是扩展到动画视图所在视图的边界之外,但是这不可能,并且可以在Draggable Views之类的东西中看到吗?

或者我刚刚接近这种情况完全错误?

怎么能真正动画超越第一个父母的边界?

在此先感谢您的帮助, -Matt

+0

是否解决了此问题?谢谢 – NoobMe

+0

使用hacky解决方案......我基本上将父级布局更改为FrameLayout,并将隐藏的Custom TextView z-放置在其他内容的上方。当我需要调用动画时,我为TextView提供与需要动画的视图相同的LayoutParams/background/text,将其设置为View.VISIBLE,对其进行动画处理,并在动画完成时将其设置回View.GONE 。我会在下面回答我的猜测 – Guardanis

回答

0

唯一的解决办法,我已经能够拿出,虽然哈克,仍然有效。

父母是一个RelativeLayout,我有一个隐藏的自定义TextView z位于其他内容上方。当我需要调用动画时,我为TextView提供与需要动画的视图相同的LayoutParams/background/text,将其设置为View.VISIBLE,对其进行动画处理,并在动画完成时将其设置回View.GONE :

public void doAnimation(final View v){  
    v.setId(5); 
    final CustomTextView animatorImage = (CustomTextView) ((MainActivity)mActivity).findViewById(R.id.pick_animator_image); // Our hidden TextView in the FrameLayout 
    try{ 
     animatorImage.setBackgroundDrawable(v.getBackground()); 
     animatorImage.setText(((TextView)v).getText().toString()); 
     animatorImage.setTextColor(((TextView)v).getCurrentTextColor()); 
     animatorImage.setTextSize(TypedValue.COMPLEX_UNIT_PX, ((TextView)v).getTextSize()); 
    } 
    catch(Exception e){ 

    } 

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(v.getWidth(), v.getHeight()); 
    int[] windowLocation = new int[2]; 
    v.getLocationInWindow(windowLocation); 

    params.leftMargin = (int) windowLocation[0]; 
    params.topMargin = (int) windowLocation[1] - ((MainActivity)mActivity).getSupportActionBar().getHeight() - getStatusBarHeight(); // Subtract the ActionBar height and the StatusBar height if they're visible 

    animatorImage.setLayoutParams(params); 
    animatorImage.setVisibility(View.VISIBLE); 

    v.setVisibility(View.INVISIBLE); 

    ScaleAnimation scaleAnim = new ScaleAnimation(1f, 2.5f, 1f, 2.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
    scaleAnim.setDuration(300); 
    scaleAnim.setZAdjustment(Animation.ZORDER_TOP); 
    scaleAnim.setAnimationListener(new AnimationListener(){ 
     public void onAnimationEnd(Animation arg0) { 

      ScaleAnimation scaleAnim2 = new ScaleAnimation(2.5f, 1f, 2.5f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
      scaleAnim2.setDuration(300); 
      scaleAnim2.setZAdjustment(Animation.ZORDER_TOP); 
      scaleAnim2.setAnimationListener(new AnimationListener(){ 
       public void onAnimationEnd(Animation animation) { 
        animatorImage.clearAnimation(); 
        v.setVisibility(View.VISIBLE); 
        animatorImage.setVisibility(View.GONE); 
       } 

       public void onAnimationRepeat(Animation animation) { 

       } 

       public void onAnimationStart(Animation animation) { 

       }}); 

      animatorImage.startAnimation(scaleAnim2); 
     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 

     } 

     @Override 
     public void onAnimationStart(Animation animation) { 

     }}); 

    animatorImage.bringToFront(); 
    animatorImage.startAnimation(scaleAnim); 
} 

的XML层次是:

RelativeLayout (parent) 
    ViewGroup (main content body) 
    TextView (hidden View to animate) 

只要改变“R.id.pick_animator_image”到无论你的TextView的ID是在RelativeLayout的,并调用该方法与你想动画视图,这会为你伪装。