ScrollView 底部的按钮,里面有 ListView

发布于 2025-01-10 14:29:42 字数 1184 浏览 2 评论 0原文

我有一个布局,类似于页面。我有一个列表视图,在列表底部我需要有一个按钮。它必须位于列表视图下,而不是粘在屏幕底部。 (就像您必须一直向下滚动列表才能获得该按钮一样。)我正在使用的结构:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <ListView
            android:id="@+id/show_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:dividerHeight="7dp"
            android:paddingHorizontal="25dp"
            android:scrollbars="none"
            android:scrollingCache="false" />
        <LinearLayout>
           //My button here
        </LinearLayout>
    </LinearLayout>
</ScrollView>

主要问题: 滚动在 ListView 的最后一项处结束,按钮保持在屏幕之外。为什么会这样呢? (我尝试使用 isVerticalScrollBarEnabled 禁用列表滚动,但没有任何区别。

编辑: 现在,当我切换了列表的顺序时按钮和列表,我发现我正在滚动ListView,而不是ScrollView,所以问题是我需要滚动ScrollView,而不是ListView。怎么做呢?

I have a layout, something like a page. I have a list view and at the bottom of the list i need to have a button. It has to be under the List View, not sticking at the bottom of the screen. (Like you have to scroll all the way down through the list to get that button.) The structure I am using:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <ListView
            android:id="@+id/show_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:dividerHeight="7dp"
            android:paddingHorizontal="25dp"
            android:scrollbars="none"
            android:scrollingCache="false" />
        <LinearLayout>
           //My button here
        </LinearLayout>
    </LinearLayout>
</ScrollView>

MAIN ISSUE: Scrolling ends at the last item of ListView, Button stays out of screen. Why is that so? (I tried disabling list scrolling with isVerticalScrollBarEnabled, but it didn't make any difference.)

EDIT: Now, as I switched order of the button and the list, I found out that I am scrolling ListView, not ScrollView, so the issue is I need to do scrolling of ScrollView, not ListView. How to do that?

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

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

发布评论

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

评论(1

舟遥客 2025-01-17 14:29:42

所以我发现 ScrollView 中的 ListView 是一种不好的做法,我使用 ListView 页脚功能代替,在单独的布局中添加按钮,然后通过代码添加它。它工作完美。

So I found out that ListView in a ScrollView is a bad practice, I used ListView footer feature instead, having button in the seperate layout, then adding it through code. It works perfectly.

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