阻止ListView滚动

时间:2011-08-09 13:18:01

标签: android android-listview footer

我有一个带有线性布局的scrollview。在该线性布局中,有一个列表视图。我遇到的问题是我的列表视图只有一定的空间,然后变得可滚动。我不希望这种情况发生。我希望显示整个列表。有谁知道我怎么做到这一点?我尝试使用此链接,但是当我添加页脚时,我的布局不会出现。 ListView in ScrollView potential workaround这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:baselineAligned="true"
    android:orientation="vertical"
    android:background="@drawable/darkimg"
    android:weightSum="1">

    <LinearLayout
        android:id="@+id/numbersLL"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:background="@drawable/round_rectangle"
        android:layout_margin="4px"
        android:paddingLeft="6px"
        android:paddingTop="3px">

        <TextView
            android:id="@+id/numberPrint"
            android:layout_height="wrap_content"
            android:textSize="14px"
            android:textStyle="bold"
            android:textColor="@color/white"
            android:layout_width="fill_parent"
            android:text="@string/numberPrint">
        </TextView>

        <ListView
            android:id="@+id/numberListView"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"></ListView>
    </LinearLayout>

</LinearLayout>
</ScrollView>

这是我的页脚:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/formLL">

<TextView
    android:id="@+id/numberFormTextViewt"
    android:layout_gravity="center_vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textSize="20px"
    android:text="Add a number:"
    android:textColor="@color/white" />

<Button
    android:id="@+id/numberFormButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_add"></Button>
</LinearLayout>

这是将页脚添加到列表的Java代码:

        LayoutInflater factory = getLayoutInflater();
        LinearLayout numberFooter = (LinearLayout) factory.inflate(R.layout.number_form, null);
        // List of numbers
        numberListView = (ListView) this.findViewById(R.id.numberListView);
        numberListView.addFooterView(numberFooter);

这里出了什么问题?显示活动时不会显示页脚。我应该提到的一件事是页脚用于将项目添加到其上方的列表中。我不确定这是否有所不同,但当我测试时,列表适配器为空。即使页脚仍然出现了吗?任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

在列表视图中尝试此操作:

android:layout_height="fill_parent"

答案 1 :(得分:0)

滚动视图下的列表视图不起作用(表示列表视图不可滚动)。

所以你可以在ur xml文件中放置空的Linear Layout而不是List视图。在您的代码中,首先您可以根据此大小值获取列表视图大小,以便循环可以旋转。在for循环中,你可以调用适配器类的get视图方法(该类不扩展任何类。)这将解决列表视图问题。

相关问题