2

In my android application activity layout I have a LinearLayout and RecyclerView, LinearLayout contains an EditText and TextField , and RecyclerView lies below the LinearLayout.

<LinearLayout 
  android:orientation="vertical">
  <LinearLayout 
    android:orientation="vertical">
     <EditText>
     <TextView>
  </LinearLayout>
  <RecyclerView/>
</LinearLayout>

at some point I have to remove the LinearLayout lies above the RecyclerView. so I am hiding that by giving some animaton effects

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

when the animation ends the view is setting to GONE. then the below RecyclerView is jumping to the top, it simply jumps without any animation and all, is there any way to manage it ? a small animaton for the layout change may help me. I have tried in xml, but it throws some error.

4

1 回答 1

6

有一种简单的方法可以为布局更改设置动画。只需将 xml 下一个属性

<LinearLayout 
    android:animateLayoutChanges="true"  <====
    android:orientation="vertical">
    <LinearLayout 
        android:orientation="vertical">
        <EditText>
        <TextView>
    </LinearLayout>
    <RecyclerView/>
</LinearLayout>

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

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

于 2015-09-03T04:27:00.783 回答