2012-04-26 9 views
0

私は、アンドロイドの相対レイアウトをアクティビティにスライドさせたいと思います。 私はレイアウトを滑り落ちる以下の機能があります:あなたが最初の行にパラメータの型のViewGroup ..My質問のある見るようアンドロイドの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); 

} 

を私はビュー・グループを参照することができますどのようにされて...

注私は、次の

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

を試みたが、これは表示しませgroupViewを返します!

+0

のViewGroupは、スーパークラスであるとして、あなたはいつものViewGroupにビューを型キャストすることができます。 –

+0

別の質問...この関数を呼び出す以外に何かをしなければならないのですか?この方法でアニメーションが始まらないので何かがありませんか? – Developer

答えて

1

ジャストタイプはViewGroupに戻り結果をキャスト、あなたのR.layout.childViewはのViewGroupから始まる、それは大丈夫だろうと提供:

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

mmm私のchildViewは相対的なレイアウトです..これは動作しますか? – Developer

+0

はい。 RelativeLayoutはViewGroup – xandy

+0

ok :)から拡張されました。なぜ、次の関数を呼び出した後にアニメーションが開始しないのですか? vg.startLayoutAnimation(); – Developer

関連する問題