2017-02-20 124 views
0

我想从屏幕底部滑动视图并折叠另一个视图一点点一切都会正确适合。平滑animateLayoutChanges动画

我设法做到这一点与属性animateLayoutChanges和2简单的xml动画slid_up.xmlslid_down.xml

我的问题是发生在ViewPager从属性animateLayoutChanges发生的动画不光滑。

有没有办法解决这个问题?

slid_up.xml

<translate 
    android:duration="1000" 
    android:fromYDelta="100%" 
    android:toYDelta="0" /> 
</set> 

slid_down.xml

<translate 
    android:duration="1000" 
    android:fromYDelta="0" 
    android:toYDelta="100%" /> 
</set> 

附:我试图创建自定义动画师作为高度动画师,但它与视图的原始高度混乱。

HeightResizeAnimation

public class HeightResizeAnimation extends Animation { 
    private View mView; 
    private float mToHeight; 
    private float mFromHeight; 
    private int duration = 300; 

    public HeightResizeAnimation(View v, float offset) { 
     mView = v; 
     mToHeight = v.getHeight() + offset; 
     mFromHeight = v.getHeight(); 
     setDuration(duration); 
    } 

    @Override 
    protected void applyTransformation(float interpolatedTime, Transformation t) { 
     float newHeight = (mToHeight - mFromHeight) * interpolatedTime + mFromHeight; 
     mView.getLayoutParams().height = (int) newHeight; 
     mView.requestLayout(); 
    } 
} 

动画后高度将不再像match_parent这是动画之前。

更新 下面是现在发生的动画 enter image description here

你可以看到晶圆厂动画到底是不是也顺利的viewpager该晶圆厂孩子

+0

你可以发布你想要动画的视频,我们会相应地更新。如果使用动画属性,则不需要requestLayout()。 –

+0

requestLayout并不完全是一个问题,HeightResizeAnimation的问题在于,如果将视图从纵向更改为横向,则高度将不再是match_parent,该位置是我添加的动画 – gmetax

+0

@AnuragSingh以及视频和gif正在播放我喜欢 – gmetax

回答

0

后,所有的解决方案是使用android:clipChildren="false"

由于可以在GIF可以看出,FAB是越来越虽然正在下降到原来的位置进行剪裁。因此,在FAB viewPager的父级上使用android:clipChildren="false"后,FAB不再被裁剪。

+1

请发布整个代码,显示你在哪里使用过android:clipChildren =“false” –

+0

如果我把所有的xml的布局放在一起,它不会很容易阅读。 – gmetax

1

好像你只是想显示一个小吃店+随着它显示移动FAB? 要做到这一点,你可以使用来自Android的支持库小吃吧和CoordinatorLayout的组合:http://www.androidhive.info/2015/09/android-material-design-snackbar-example/

+0

的动画,所以'喜欢!'是一个小吃店,所以它就像吐司一样。非常感谢您的回答,但这不是我想要的。 – gmetax

+0

嗨@gmetax,看着更新的动画我仍然会说它应该是一个小吃店,但里面有自定义视图(https://material.io/guidelines/components/snackbars-toasts.html#)你可以检查这个out:http://stackoverflow.com/questions/32453946/how-to-customize-snackbars-layout使用快餐栏可能会帮助你平滑的动画,因为它显示在其他视图的顶部,它不会改变下方视图的高度。 –

+0

但小吃店是有时间限制的。 :/ – gmetax

1

在XML布局中添加以下的观点:

android:visibility="gone" 
android:alpha="0" 
android:id="@+id/text_view_liked" 

我asumming的观点是TextView 。 论ImageView点击喜欢动画text_view_liked有以下几点:

final TextView textViewLiked = (TextView) findViewById(R.id.text_view_get_liked); 
    final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 

    PropertyValuesHolder pvhYTextViewLiked = PropertyValuesHolder 
     .ofFloat(View.Y, 
      textViewLiked.getBottom(), 
      (textViewLiked.getBottom() - textViewLiked.getHeight())); 

    PropertyValuesHolder pvhAlphaTextViewLiked = PropertyValuesHolder 
     .ofFloat(View.ALPHA, 0f, 1f); 

    ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(textViewLiked, 
     pvhYTextViewLiked, 
     pvhAlphaTextViewLiked); 

    ObjectAnimator objectAnimatorFab = ObjectAnimator.ofFloat(fab, View.Y, fab.getY(), 
     fab.getY() - textViewLiked.getHeight()); 

    AnimatorSet animatorSet = new AnimatorSet(); 
    animatorSet.play(objectAnimator).with(objectAnimatorFab); 
    animatorSet.addListener(new AnimatorListenerAdapter() { 

     @Override 
     public void onAnimationStart(Animator animation) { 
     super.onAnimationStart(animation); 
     textViewLiked.setVisibility(View.VISIBLE); 
     } 

     @Override 
     public void onAnimationEnd(Animator animation) { 
     super.onAnimationEnd(animation); 

     new Handler().postDelayed(new Runnable() { 
      @Override 
      public void run() { 

      PropertyValuesHolder pvhYTextViewLiked = PropertyValuesHolder 
       .ofFloat(View.Y, 
        textViewLiked.getTop(), 
        (textViewLiked.getTop() + textViewLiked.getHeight())); 

      PropertyValuesHolder pvhAlphaTextViewLiked = PropertyValuesHolder 
       .ofFloat(View.ALPHA, 1f, 0f); 

      ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(textViewLiked, 
       pvhYTextViewLiked, 
       pvhAlphaTextViewLiked); 

      ObjectAnimator objectAnimatorFab = ObjectAnimator.ofFloat(fab, View.Y, fab.getY(), 
       fab.getY() + textViewLiked.getHeight()); 

      AnimatorSet animatorSet = new AnimatorSet(); 
      animatorSet.play(objectAnimator).with(objectAnimatorFab); 
      animatorSet.addListener(new AnimatorListenerAdapter() { 
       @Override 
       public void onAnimationEnd(Animator animation) { 
       super.onAnimationEnd(animation); 
       textViewLiked.setVisibility(View.GONE); 
       } 
      }); 
      animatorSet.start(); 
      } 
     }, 1000); 

     } 
    }); 

您可以相应地调整

new Handler仅创建了自动化进度指示器的完成过程的持续时间。您可以调用进度指示器的结束。

+0

你不明白这个问题。我不想创建完全像'喜欢!',但这是在视频中显示。如果我想创造'喜欢!'我会与@Piotr Zawadzki回答。但试过你的答案,检查晶圆厂是否会有一个更流畅的动画,但它没有。 – gmetax

+0

小吃店的持续时间有限。你想在里面显示进度指示器。我的视图可以是视图组。但小吃店不能。此外,Snacbar宽度无法覆盖平板电脑的整个屏幕宽度。另外,请让我知道我错过了什么。当视图平滑过渡时,您是否想要上下移动晶圆厂? –

+0

您的示例基于“喜欢!”视图。我知道小吃棒的局限性,我知道我不能按需要使用它。如果你在我的问题上看到gif,你会发现晶圆厂不能顺利移动,viewpager(白色背景)也不能顺利移动 – gmetax