Я хочу анимировать появление фрагмента. При чем чтобы он появлялся "сверху вниз". Мне частично удалось реализовать задумку, но проблема в том что сначала появляется место на экране под фрагмент, а только потом появляется сам фрагмент с анимацией. Как сделать одновременную анимацию появления места на экране и анимацию появления фрагмента?
Вот что имею:
Экран разметки
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical"
tools:context="simpleproject.diary.MainScreenTableView">
<include
android:id="@+id/toolbar"
layout="@layout/two_lines_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible" />
<FrameLayout
android:id="@+id/calendarView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
</FrameLayout>
<include
layout="@layout/recyclerview_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp" />
</LinearLayout>
Методы, запускающие анимацию
private void calendarShow() {
FragmentTransaction t = getSupportFragmentManager().beginTransaction();
t.setCustomAnimations(R.animator.calendar_show, R.animator.calendar_hide);
t.replace(R.id.calendarView, mCalendar, CALENDAR_TAG);
t.show(mCalendar);
t.commit();
mCalendar.refreshView();
}
private void calendarHide() {
android.support.v4.app.FragmentTransaction t = getSupportFragmentManager().beginTransaction();
t.setCustomAnimations(R.animator.calendar_show, R.animator.calendar_hide);
t.hide(getSupportFragmentManager().findFragmentByTag(CALENDAR_TAG));
t.commit();
}
Анимации появления и исчезновения
calendar_show.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="y"
android:valueFrom="-1000"
android:valueTo="0"
android:valueType="floatType" />
</set>
calendar_hide.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="y"
android:valueFrom="0"
android:valueTo="-1000"
android:valueType="floatType" />
</set>