调用 Class 在 RelativeLayout child 中显示 Table

Calling a Class to display a Table inside RelativeLayout child

我有问题。

我有一个复杂的class谁创造了一个大table:

Table(Context context,String[][] matrix)

我使用以下说明从 ActivityMain 调用 class:

 Table table = new Table(this,Matrix);
 setContentView(table);

并且完美地将 table 扩展到所有屏幕。

问题来了。现在我想要一些 space 用于工具栏菜单,所以我修改 XML 以这样创建它:

RelativeLayout

          Toolbar Menu (child)

          RelativeLayout (child)

RelativeLayout

但是当我调用 class 来创建 table 时,它仍然展开了整个屏幕,我看不到菜单。我的想法是在工具栏菜单下方的第二个 RelativeLayout 中创建 Table。

但是我不知道放在这里做什么:

Table table = new Table(_____HERE______,Matrix);

 setContentView(table);

我不想修改class Table,所以在ActivityMain中有一种方法可以在第二个[=]中显示table 18=] 让我看看 ToolbarMenu?

谢谢!!

您不是在布局中添加 Table,而是替换它。

解决它的最简单方法是在 activity 布局中创建一个容器 layout 例如 FrameLayout 并在其中添加 Table

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:id="@+id/toolbar"/>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar"
        android:id="@+id/container"/>

</RelativeLayout>

然后在你的 activity 中做:

setContentView(R.layout.main_activity);

FrameLayout container = (FrameLayout) findViewById(R.id.container);
container.addView(new Table(this,Matrix));