Listview 下方的 TableLayout 不显示
TableLayout below Listview not displaying
我想在 Listview
下方显示 TableLayout
( 其中项目的数量是动态添加的 )。我之前提到过类似的问题,但它对我不起作用。我正在使用 android:layout_below
将 TableLayout
设置在 Listview
下方,但它仍然不起作用,我将不胜感激任何指导我如何执行此操作的人。
这是我的代码:
<?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>
好的。因此,根据我们在评论部分关于查看您的代码的讨论,您似乎希望 ListView
和 TableLayout
具有相等的 height(因为您将 layout_weight
包含在它们 中)。
因此,为了产生您想要的输出,请执行以下操作。
使用 RelativeLayout
作为父布局。
添加一个LinearLayout
,weightSum
= 2 和orientation=vertical
,并把ListView
和TableLayout
放在里面,它们的高度 = 0dp 和 layout_weight
= 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 预览中检查布局时的显示,而不是代码为运行 时的显示。
我想在 Listview
下方显示 TableLayout
( 其中项目的数量是动态添加的 )。我之前提到过类似的问题,但它对我不起作用。我正在使用 android:layout_below
将 TableLayout
设置在 Listview
下方,但它仍然不起作用,我将不胜感激任何指导我如何执行此操作的人。
这是我的代码:
<?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>
好的。因此,根据我们在评论部分关于查看您的代码的讨论,您似乎希望 ListView
和 TableLayout
具有相等的 height(因为您将 layout_weight
包含在它们 中)。
因此,为了产生您想要的输出,请执行以下操作。
使用
RelativeLayout
作为父布局。添加一个
LinearLayout
,weightSum
= 2 和orientation=vertical
,并把ListView
和TableLayout
放在里面,它们的高度 = 0dp 和layout_weight
= 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 预览中检查布局时的显示,而不是代码为运行 时的显示。