【问题标题】:How to add elements after a ListView in Android如何在 Android 中的 ListView 之后添加元素
【发布时间】:2012-05-21 16:49:10
【问题描述】:

以下是我对 XML 的看法。 (我只添加了结构)。问题是当列表视图中的元素很少(动态生成)时,输出将显示直到最后一个按钮的所有内容。但是一旦视图增长通过列表视图之后的屏幕大小元素就不会显示。但是列表视图中的所有元素都会出现。如何通过更改此 XML 来修复它。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TableRow >
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    </TableRow>
</TableLayout>
<ListView 
    android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
</ListView>
<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TableRow >
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    </TableRow>
</TableLayout>
<Button 
     android:layout_height="wrap_content"
     android:layout_width="fill_parent" />
<Button 
     android:layout_height="wrap_content"
     android:layout_width="fill_parent"/>
</LinearLayout>

【问题讨论】:

标签: android android-layout


【解决方案1】:

ListView 渴望身高。呈现ListView 的最坏情况是给它高度wrap_content

随着 ListView 中的项目变大,ListView 会增加其高度以包裹其内容,因此会将其他 Views 推出屏幕。

我建议您将其高度设置为 fill_parent 并使用 layout_weight 参数。

为了进一步参考,我建议您阅读this article 了解使用RelativeLayout 调整ListView 与其他ViewViewGroup

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-11
    • 2018-10-30
    • 2011-05-31
    • 2011-01-15
    • 1970-01-01
    相关资源
    最近更新 更多