1

我有一个基于 ViewGroup 的飞行菜单。我希望会有一个基本布局,并且在任何活动中我都可以将新布局插入到视图组中,然后将其删除。 但它不起作用!你能帮我吗。

班级:

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

视图组:

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

提前致谢

4

1 回答 1

0

Try overriding the setContentView(int) instead of the onCreate(Bundle).

Make sure your base layout XML has a ViewGroup (FrameLayout, for example) available to put each Activity's content.

When overriding the setContentView(int), inflate your base layout first then inflate the Activity's layout and place the Activity's layout on the FrameLayout available.

于 2013-08-23T19:17:57.633 回答