如何在Android Studio中将ListView放置在ScrollView内?

huangapple 未分类评论48阅读模式
英文:

How can I put a listView inside a scroll view on android studio?

问题

我无法滚动位于滚动视图内部的列表视图。我尝试过使用嵌套滚动视图,但仍无法正常工作。希望我能在这里得到一些帮助 如何在Android Studio中将ListView放置在ScrollView内?

英文:

I can't scroll the list view that is inside the scroll view.I tried using nested scroll view but it still dosen't work. hope I'll get some help here 如何在Android Studio中将ListView放置在ScrollView内?

答案1

得分: 0

一般来说,不建议使用这种技术。您可以在ListView中使用Headers和Footers来消除对scrollView的使用。

如果您仍然坚持在ScrollView内部使用ListView(不推荐),以下是一个技巧:
https://stackoverflow.com/questions/18367522/android-list-view-inside-a-scroll-view

TLDR;
在任何ChildView中实现在ScrollView内滚动的最短且最简单的解决方案。无论是ListView、RecyclerView等,您无需在代码中做任何特殊处理。

只需将ScrollView替换为android.support.v4.widget.NestedScrollView,放入您当前的xml中,然后魔术就会发生。

英文:

Generally, It is not recommended to use this technique. You can use your ListView with Headers and Footers to eliminate the use of scrollView.

If you are still bent on using ListView inside ScrollView(Not recommended). Here is a hack:
https://stackoverflow.com/questions/18367522/android-list-view-inside-a-scroll-view

TLDR;
The shortest & easiest solution for any ChildView to scroll inside a ScrollView. Anything like ListView, RecyclerView, etc. You do not have to do anything special in code.

Just replace ScrollView with android.support.v4.widget.NestedScrollView in your current xml and then magic happens.

huangapple
  • 本文由 发表于 2020年4月11日 01:28:49
  • 转载请务必保留本文链接:https://java.coder-hub.com/61145481.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定