Advertisement
Guest User

NowLayout

a guest
Mar 13th, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. import android.content.Context;
  2. import android.util.AttributeSet;
  3. import android.view.View;
  4. import android.view.animation.AnimationUtils;
  5. import android.widget.LinearLayout;
  6.  
  7. public class NowLayout extends LinearLayout {
  8.  
  9.     public NowLayout(Context context, AttributeSet attrs) {
  10.         super(context, attrs);
  11.  
  12.     }
  13.  
  14.     public NowLayout(Context context) {
  15.         super(context);
  16.     }
  17.  
  18.     public void switchFrame(bool flyIn) {
  19.  
  20.         final int heightPx = getContext().getResources().getDisplayMetrics().heightPixels;
  21.  
  22.         boolean inversed = false;
  23.         final int childCount = getChildCount();
  24.  
  25.         for (int i = 0; i < childCount; i++) {
  26.             View child = getChildAt(i);
  27.  
  28.             int[] location = new int[2];
  29.  
  30.             child.getLocationOnScreen(location);
  31.  
  32.             if (location[1] > heightPx) {
  33.                 break;
  34.             }
  35.  
  36.             if (flyIn) {
  37.                 if (!inversed) {
  38.                     child.startAnimation(AnimationUtils.loadAnimation(getContext(),
  39.                             R.anim.slide_up_left));
  40.                 } else {
  41.                     child.startAnimation(AnimationUtils.loadAnimation(getContext(),
  42.                             R.anim.slide_up_right));
  43.                 }
  44.             } else {
  45.                 if (!inversed) {
  46.                     child.startAnimation(AnimationUtils.loadAnimation(getContext(),
  47.                             R.anim.slide_out_left));
  48.                 } else {
  49.                     child.startAnimation(AnimationUtils.loadAnimation(getContext(),
  50.                             R.anim.slide_out_right));
  51.                 }
  52.             }
  53.  
  54.             inversed = !inversed;
  55.         }
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement