2012-04-26 26 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