代码之家  ›  专栏  ›  技术社区  ›  powerj1984

在Android中使用包含标签的多个布局

  •  3
  • powerj1984  · 技术社区  · 16 年前

    我正在尝试创建一个标题栏,它在整个应用程序中都是相同的,并且一直在为我的每个活动创建这样的布局:

    main.xml文件:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent" android:layout_height="fill_parent">
     <include layout="@layout/title_bar_layout" android:id="@+id/title_bar_layout" />
     <include layout="@layout/main_body" android:id="@+id/main_body" />
    </LinearLayout>
    

    正文.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/main_table" android:layout_width="fill_parent"
     android:layout_height="fill_parent" android:stretchColumns="1"
     android:orientation="vertical">
    </TableLayout>
    

    setContentView(R.layout.main);
    TableLayout t = (TableLayout) findViewById(R.id.main_table);
    

    但是t总是以空结束。

    1 回复  |  直到 16 年前
        1
  •  3
  •   Pete    11 年前

    试试看:

    TableLayout t = (TableLayout) findViewById(R.id.main_body);
    

    从这个 page

    您可以使用android:id指定 包含的根视图的id 布局;它还将覆盖id 定义