0

I want to slide down a Relative layout in android withen an activity. I have the following function that slides down a layout:

public void setLayoutAnim_slidedown(ViewGroup panel, Context ctx) {

    AnimationSet set = new AnimationSet(true);

    Animation animation = new TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, -1.0f,
            Animation.RELATIVE_TO_SELF, 0.0f);
    animation.setDuration(800);
    animation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub
            // MapContacts.this.mapviewgroup.setVisibility(View.VISIBLE);

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationEnd(Animation animation) {

            // TODO Auto-generated method stub

        }
    });
    set.addAnimation(animation);

    LayoutAnimationController controller = new LayoutAnimationController(
            set, 0.25f);
    panel.setLayoutAnimation(controller);

}

as you see the parameter in the first line is of type ViewGroup ..My question is how can I reference the View group ...

Note I tried the following

                LayoutInflater inflater = (LayoutInflater) myContext
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View v = inflater.inflate(R.layout.childView, null);

But this returns View not a groupView !

Developer
  • 1,803
  • 2
  • 15
  • 26
  • you can always typecast View to Viewgroup as ViewGroup is super class. – N-JOY Apr 26 '12 at 09:16
  • another question ... Do I have to do any thing extra than calling the function .. because the animation doesn't start by this way .. is there any thing missing? – Developer Apr 26 '12 at 09:32

1 Answers1

1

Just type cast the return result to ViewGroup, provided that your R.layout.childView starts with a ViewGroup, it would be fine:

ViewGroup vg = (ViewGroup )inflater.inflate(R.layout.childView, null);
xandy
  • 27,357
  • 8
  • 59
  • 64