2012-04-26 46 views
0

我想在一个activity中向下滑动android中的Relative布局。 我有以下功能滑下布局:在android中引用ViewGroup

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); 

} 

当你看到第一行中的一个参数的类型的ViewGroup ..My问题是我怎么能引用视图组...

注意我试过以下

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

但是,这返回查看不是groupView!

+0

可以随时查看类型转换到一个ViewGroup作为一个ViewGroup是超一流的。 – 2012-04-26 09:16:46

+0

另一个问题...我是否必须做比调用函数更多的东西......因为动画不是以这种方式开始的......有什么遗漏吗? – Developer 2012-04-26 09:32:24

回答

1

只需键入转换返回结果ViewGroup,前提是你的R.layout.childView与ViewGroup中开始,这将是罚款:

ViewGroup vg = (ViewGroup)inflater.inflate(R.layout.childView, null); 
+0

mmm我的childView是一个相对的布局..这是否工作? – Developer 2012-04-26 09:16:51

+0

是的。 RelativeLayout扩展自ViewGroup – xandy 2012-04-26 09:51:22

+0

好吧:)为什么在调用以下内容后动画不会启动? vg.startLayoutAnimation(); – Developer 2012-04-26 09:56:02

相关问题