ScrollView 底部的按钮,里面有 ListView
我有一个布局,类似于页面。我有一个列表视图,在列表底部我需要有一个按钮。它必须位于列表视图下,而不是粘在屏幕底部。 (就像您必须一直向下滚动列表才能获得该按钮一样。)我正在使用的结构:
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以我发现 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.