0

I am working on Fragments translate animation by following link : http://trickyandroid.com/fragments-translate-animation/

But i want to start slide down animation by pressing back button rather finishing slide up animation by pressing Action bar button .

Slide_down.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
            android:interpolator="@android:anim/accelerate_decelerate_interpolator"
            android:propertyName="yFraction"
            android:valueType="floatType"
            android:valueFrom="0.58"
            android:valueTo="1.0"
            android:duration="@android:integer/config_mediumAnimTime"/>
    <objectAnimator
            android:interpolator="@android:anim/accelerate_decelerate_interpolator"
            android:propertyName="alpha"
            android:valueType="floatType"
            android:valueFrom="1"
            android:valueTo="0"
            android:duration="@android:integer/config_mediumAnimTime"/>
</set>

Slide.up.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <objectAnimator
            android:interpolator="@android:anim/accelerate_decelerate_interpolator"
            android:propertyName="yFraction"
            android:valueType="floatType"
            android:valueFrom="1.0"
            android:valueTo="0.58"
            android:duration="@android:integer/config_mediumAnimTime"/>
    <objectAnimator
            android:interpolator="@android:anim/accelerate_decelerate_interpolator"
            android:propertyName="alpha"
            android:valueType="floatType"
            android:valueFrom="0.58"
            android:valueTo="1.0"
            android:duration="@android:integer/config_mediumAnimTime"/>
</set>

Code for Animation in Main Activity:

 Fragment f = getFragmentManager().findFragmentByTag(LIST_FRAGMENT_TAG);



        if (f != null) {
            getFragmentManager().popBackStack();
        } else {
            getFragmentManager().beginTransaction()
                    .setCustomAnimations(R.anim.slide_up,
                            R.anim.slide_down,
                            R.anim.slide_up,
                            R.anim.slide_down)
            .add(R.id.list_fragment_container, SlidingListFragment
                            .instantiate(this, SlidingListFragment.class.getName()),
                    LIST_FRAGMENT_TAG
            )
               .addToBackStack(null) .commit();

            googleMap.getUiSettings().setAllGesturesEnabled(false);
            }


        }

Please help me to increase my knowledge regarding this .

young_08
  • 1,196
  • 2
  • 13
  • 35
  • @Sandeep Patidar : Hello , i have seen your comment in http://stackoverflow.com/questions/18119122/custom-activity-transition-animation-in-android . Just wanna ask , is this would be solution for my problem too ? – young_08 Oct 12 '15 at 05:41
  • try `Handler.postDelayed` – Neil Oct 12 '15 at 05:55
  • @Neil: As per my knowledge , Handler.postDeleayed use for queue up the task . Am i right ? i don't want to delay it , I want to animate slide down on pressing back button . Id i get you wrong . please help me with code for better understanding . Thank you . – young_08 Oct 12 '15 at 06:05

1 Answers1

0

Handler can be used as a lightweight timer. The key is animation will be clear as soon as activity start performing a finish, so you have to delay the finish in order to see the animation completely.

  new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            MainActivity.super.onBackPressed();
        }
    }, getResources().getInteger(android.R.integer.config_mediumAnimTime));
Neil
  • 664
  • 6
  • 16
  • But for this , there should be code onBackPressed() which slide down the animation when its slide up on screen ? What would be that ?OverridingPending()? – young_08 Oct 12 '15 at 06:32
  • `overridePendingTransition` is for activity, actually fragment transition is just general view animation. – Neil Oct 12 '15 at 06:41
  • Then this should i need to add , i guess to achieve what i want ? public void onBackPressed() { overridePendingTransition(R.anim.slide_down,R.anim.slide_down); } – young_08 Oct 12 '15 at 06:44