布局更改发生时的动画

dro*_*dev 2 android android-layout layout-animation android-recyclerview

在我的Android应用程序活动布局中,我有一个LinearLayout和RecyclerView,LinearLayout包含一个EditText和TextField,而RecyclerView位于LinearLayout下面.

<LinearLayout 
  android:orientation="vertical">
  <LinearLayout 
    android:orientation="vertical">
     <EditText>
     <TextView>
  </LinearLayout>
  <RecyclerView/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

在某些时候,我必须删除RecyclerView上方的LinearLayout.所以我通过给出一些动画效果来隐藏它

LinearLayout.animate().translationY(-LinearLayout.getHeight()).setInterpolator(new DecelerateInterpolator()).alpha(0.0f).setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                LinearLayout.setVisibility(View.GONE);
            }
        }).setDuration(HEADER_HIDING_ANIMATION_DURATION);
Run Code Online (Sandbox Code Playgroud)

当动画结束时,视图设置为GONE.然后下面的RecyclerView跳到顶部,它只是跳转而没有任何动画,所有,有没有办法管理它?布局改变的小型动画师可能对我有所帮助.我试过xml,但它会引发一些错误.

Ily*_*kov 6

有一种简单的方法可以为布局更改设置动画.只需输入xml next属性即可

<LinearLayout 
    android:animateLayoutChanges="true"  <====
    android:orientation="vertical">
    <LinearLayout 
        android:orientation="vertical">
        <EditText>
        <TextView>
    </LinearLayout>
    <RecyclerView/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

然后在代码中将第二个LinearLayout的可见性更改为GONE/VISIBLE.

更多信息可以在这里找到:链接到Android文档