Android Listview下方的TableLayout未显示

Android Listview下方的TableLayout未显示,android,android-layout,listview,android-tablelayout,Android,Android Layout,Listview,Android Tablelayout,我想在列表视图下方显示一个表格布局(其中动态添加了项数)。我以前提过一个类似的问题,但对我来说不起作用。我正在使用下面的android:layout_来设置Listview下面的TableLayout,但它仍然不起作用,我希望有人能指导我怎么做 这是我的密码: <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://

我想在
列表视图
下方显示一个
表格布局
(其中动态添加了项数)。我以前提过一个类似的问题,但对我来说不起作用。我正在使用下面的
android:layout_
来设置
Listview
下面的
TableLayout
,但它仍然不起作用,我希望有人能指导我怎么做

这是我的密码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />


    </android.support.design.widget.AppBarLayout>

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:clipToPadding="false"
        android:divider="@color/list_divider"
        android:dividerHeight="10.0sp"
        android:listSelector="@drawable/list_row_selector"
        android:paddingBottom="100dip"
        android:paddingTop="70dip" />

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/list"
        android:layout_weight="1">

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="20dp">

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Total Items"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <TextView
                android:id="@+id/textView11"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="idvalue_text"
                android:textAppearance="?android:attr/textAppearanceLarge" />

        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="20dp">

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Total Cost"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <TextView
                android:id="@+id/textView21"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="idvalue_text"
                android:textAppearance="?android:attr/textAppearanceLarge" />

        </TableRow>

    </TableLayout>
</android.support.design.widget.CoordinatorLayout>

好的。因此,根据我们在评论部分关于查看代码的讨论,您似乎希望
列表视图
表格布局
具有相同的高度(因为您将
布局(权重
)都包括在内)

因此,为了产生所需的输出,请执行以下操作

  • 使用
    RelativeLayout
    作为父布局

  • 添加一个
    LinearLayout
    ,其中
    weightSum
    =2和
    orientation=vertical
    ,并将
    ListView
    TableLayout
    放在其中,其中高度均为0dp,布局权重均为1

  • 以下是一个示例片段供您参考:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    
        </android.support.design.widget.AppBarLayout>
    
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:weightSum="2">
    
            <ListView
                android:id="@+id/list"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />
    
            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_below="@id/list"
                android:layout_weight="1">
    
            </TableLayout>
    
        </LinearLayout>
    
    </RelativeLayout>
    
    
    


    PS:这只是在Android Studio预览中检查布局时的显示,而不是在代码运行时

    为什么您更喜欢使用
    协调布局
    而不是
    相对布局
    <下面的代码>布局参数不适用于
    协调布局
    ,仅适用于
    相对布局
    ,请参见此处获取
    布局参数
    的信息。此外,如果您提供指向您所指问题的链接,也会有所帮助。@9月我已将坐标布局更改为相对布局,然后下面的布局也不起作用。我注意到所有子视图的宽度和高度都设置为
    match\u parent
    /
    fill\u parent
    ,我认为可能会显示
    TableLayout
    ,但它不可见,因为
    ListView
    占用了所有空间?@sept yes TableLayout不可见,我应该如何使其可见并将其设置在ListView下方取决于您希望它的外观。。您希望它的
    列表视图
    表格布局
    的高度相同吗?您对布局是新手吗?我添加了一个代码片段供您参考。祝你好运和幸福。:)