0

I am trying to execute an animation in which I have two fragments stacked on top of each other.

The top fragment is a details fragment. the bottom fragment is a menu list view fragment.

I did this by creating two overlapping framelayouts in the activity layout. I want to be able to do an animation in which the background fragment would be revealed in a fashion similar to a door opening leaving only 20 percent of the edge of the top fragment in view.

I tried doing this animation with the standard view animation library available to API 9 but it seemed that only the pixels were moved and but the touch mapping still corresponded to the top fragment and the bottom menu fragment could not be accessed.

So I downloaded the nineoldandroids library and tried to user AnimatorSet with ObjectAnimators to do the animation... except this time when the fragment is animated away it reveals only a gray background rather than the fragment in the back like before.

This is a code snippet on how I tried to implement a simple translation to reveal the background fragment

  private void animateFragmentOut() {
        activeFragment = (Fragment)getSupportFragmentManager().findFragmentById(R.id.nav_item_fragment_container);
        View myView = activeFragment.getView();
    AnimatorSet set = new AnimatorSet();
    set.playTogether(
            ObjectAnimator.ofFloat(myView, "translationX", 0, 230)
    );
    set.setDuration(500).start();

}

Why is the background fragment not shown when I use this animation? How do I use nineoldandroids to reveal the background fragment properly?

feilong
  • 1,564
  • 3
  • 16
  • 22

1 Answers1

0

I ended up solving this problem by using a listener to inflate the background view right at the start of the animation using the following code

private void animateFragmentOut() {
        activeFragment = (Fragment)getSupportFragmentManager().findFragmentById(R.id.nav_item_fragment_container);
        View myView = activeFragment.getView();

    Animator.AnimatorListener listener = new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            launchNavigationFragment();
        }

        @Override

        public void onAnimationEnd(Animator animation) {
        }
    };


    ObjectAnimator rotateY = ObjectAnimator.ofFloat(myView,"rotationY",-15f);
    ObjectAnimator scaleX = ObjectAnimator.ofFloat(myView,"scaleX",0.8f);
    ObjectAnimator scaleY = ObjectAnimator.ofFloat(myView,"scaleY", 0.8f);
    ObjectAnimator translateX = ObjectAnimator.ofFloat(myView,"translationX",400f);

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(rotateY,scaleX,scaleY,translateX);
    animatorSet.addListener(listener);
    animatorSet.setDuration(700);
    animatorSet.start();
}

Saldy despite this working great on API levels 11> and up on my API 9 device I am still having the same problem I had with the standard animation library. The view pixels translate but the touch areas stay mapped in the same place. So I cannot interact with the background navigation menu fragment.

feilong
  • 1,564
  • 3
  • 16
  • 22
  • this is because both std Animations and nineoldandroid only draw the views in animated form but in any case they dont physically transform the views (there is only "look" not "look and feel") – pskink Sep 05 '14 at 21:20
  • So I am stuck calculating the new position for the old APIs huh? Is there any good resources on how to do this? I have been trying but I don't think I have a good understanding on how everyone is doing that – feilong Sep 05 '14 at 21:26
  • the standard way for Animations is to setup an animation listener, startAnimation() and in onAnimationEnd move the view to a new position – pskink Sep 05 '14 at 21:39
  • I understand that but when i try to do something like FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(myView.getWidth(),myView.getHeight()); myView.setLayoutParams(lp); it doesnt seem to work – feilong Sep 05 '14 at 21:44