防止ListView滚动

发布于 2024-11-29 04:36:08 字数 3046 浏览 1 评论 0原文

我有一个带有线性布局的滚动视图。在该线性布局中有一个列表视图。我遇到的问题是我的列表视图只有一定的空间,然后变得可滚动。我不希望这种事发生。我希望显示整个列表。有谁知道我如何实现这一目标?我尝试使用此链接,但是当我添加页脚时,我的布局没有出现。 ​​ScrollView 中的 ListView 潜在解决方法 这是我的代码:

<?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);

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

I have a scrollview with a linear layout in it. Within that linear layout there is a list view. The problem I am having is that my list view only has a certain amount of space and then becomes scrollable. I don't want this to happen. I want the entire list to be shown. Does anyone know how I might achieve this? I have tried using this link however my layout does not appear when I add the footer. ListView in ScrollView potential workaround This is my code:

<?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>

This is my footer:

    <?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>

And this is the Java code to add the footer to the list:

        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);

What is going wrong here? The footer does not appear when the activity is displayed. One thing I should mention is the footer is used to add items to the list above it. I'm not sure if that makes a difference but when I am testing this the list adapter is empty. Even still should the footer show up anyway? Any help would be appreciated thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心头的小情儿 2024-12-06 04:36:08

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

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

List view under scroll view is not working(means List view is not scrollable).

So u can put empty Linear Layout instead of List view in ur xml file. In ur code, first u can get the list view size, based on this size value, for loop can rotated. In that for loop u can call the get view method of the adapter class(that class is not extending any class.) this will solve the list view problem.

红颜悴 2024-12-06 04:36:08

在你的列表视图中尝试这个:

android:layout_height="fill_parent"

try this in your listview:

android:layout_height="fill_parent"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文