3

i have been stumped on this for quite a while now. I am trying to move my fragment which is contained in a FrameLayout, to the right, so that only the left 20% of the fragment is visible.

The problem I think I am running into is that the parent won't let the fragment move outside its bounds, or I do not know how to move it. Everything I have tried has just shoved the fragment up against the right wall, and scaling the fragment to fit. I need it to push the fragment outside the right wall. Any help would be more than appreciated.

The final effect I am trying to achieve, is that when you push a put-on the fragment translates into full view, and then with the push of a button translates back to 20% view. i have the animation all set up, just the actual moving of the fragment is stumping me.

WIllJBD
  • 6,144
  • 3
  • 34
  • 44
  • What do you mean by "i have the animation all set up, just the actual moving of the fragment is stumping me"? Those statements seem mutually contradictory. You might also take a peek at this question I asked (and answered, along with other answers) a month or two ago: http://stackoverflow.com/questions/12253965/complete-working-sample-of-the-gmail-three-fragment-animation-scenario – CommonsWare Oct 11 '12 at 23:09
  • It means that although it animates, that does not mean the fragment itself is where the animation makes it appear to be. It will still receive OnClick events at the original position until it is physically moved. – WIllJBD Oct 11 '12 at 23:14
  • Also that example does not help me, I am trying to move it partially off screen, not just scrunch it up against an edge. – WIllJBD Oct 11 '12 at 23:15

1 Answers1

2

It means that although it animates, that does not mean the fragment itself is where the animation makes it appear to be. It will still receive OnClick events at the original position until it is physically moved.

You are probably using old-style animations (e.g., TranslateAnimation), which were designed for transient effects, not permanent ones.

The reason I pointed you to a related question of mine was that many of the solutions, including my own solution use the new animator framework, which is designed for longer-lasting effects.

Also that example does not help me, I am trying to move it partially off screen, not just scrunch it up against an edge.

Particularly with respect to the animator framework, there is no material difference between "move it partially off screen" and "scrunch it up against an edge". For example, if you had read my solution, you would have seen a translateWidgets() method demonstrating a horizontal slide of a set of widgets:

private void translateWidgets(int deltaX, View... views) {
    for (final View v : views) {
      v.setLayerType(View.LAYER_TYPE_HARDWARE, null);

      v.animate().translationXBy(deltaX).setDuration(ANIM_DURATION)
       .setListener(new AnimatorListenerAdapter() {
         @Override
         public void onAnimationEnd(Animator animation) {
           v.setLayerType(View.LAYER_TYPE_NONE, null);
         }
       });
    }
  }

In your case, deltaX would be whatever the appropriate value is to achieve your 20% effect (presumably 0.2f times the container's width, or something along those lines), or to undo that effect when the full fragment should be seen.

My answer contains links to full sample projects, both for the native API Level 11 animators, and using the NineOldAndroids backport of the animator framework.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491