2013-08-23 41 views
1

我有一个基于ViewGroup的菜单。 我想要有一个基本的布局,并且在任何活动中,我都可以插入到视图组中,然后再删除它。 但它不工作!你能帮我吗?将布局添加到ViewGroup Android

类:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    this.root = (FlyOutContainer) this.getLayoutInflater().inflate(R.layout.activity_main, null); 

    this.setAdditionalLayout(findViewById(R.id.physical_layout)); 

    this.setContentView(root); 
} 

的ViewGroup:

<com.nurielweizmann.calculator.view.viewgroup.FlyOutContainer xmlns:android="http://schemas.android.com/apk/res/android" 
                   android:layout_width="match_parent" 
                   android:layout_height="match_parent"> 
<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#444488" 
     android:orientation="vertical" 
     android:id="@+id/menu"> 
............ 
</RelativeLayout> 
</com.nurielweizmann.calculator.view.viewgroup.FlyOutContainer> 

功能:提前

FlyOutContainer root; 
    public void setAdditionalLayout(View view){ 
     root.addView(view,1); 
    } 

感谢

回答

0

尝试重写setContentView(int)代替onCreate(Bundle)

确保您的基本布局XML有一个ViewGroup(例如,FrameLayout)可用于放置每个Activity的内容。

当重写setContentView(int),第一膨胀你的基地布局,然后吹大Activity的布局和放置Activity的布局上可用的FrameLayout