【发布时间】:2016-11-13 14:27:39
【问题描述】:
我想要我的 RecyclerView 到 wrap_content。我不想在 RecyclerView 内进行任何滚动,它应该调整到内部孩子的高度。我不希望我的父 ScrollView 滚动我的活动内容。
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- scrolls a little bit as RecyclerView goes slightly down beyond the screen -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- still scrolls inside -->
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
填充 RecyclerView:
myAdapter = new MyAdapter();
layoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(myAdapter);
我使用 RecyclerView 库,应该修复 wrap_content 问题:
dependencies {
compile 'com.android.support:recyclerview-v7:25.0.0'
}
基本上 RecyclerView 的高度计算对我来说并不适用。 RecyclerView 仍然有它自己的滚动,并且 ScrollView 也有一点滚动。如果我尝试将一些可笑的 RecyclerView 高度设置为 1000dp,使其大于项目的总高度,则滚动会根据需要工作,例如RecyclerView 不滚动,ScrollView 滚动带有所有 RecyclerView 项的活动。
那么我做错了什么? :)
【问题讨论】:
-
这在 v25 之前有效吗?
-
请通过此链接找到解决方案enter link description here
-
@natario afaik >v23 中存在错误,但已修复且 wrap_content 应按预期工作。
-
@KiranNemani 我不想在 RecyclerView 中禁用滚动。我希望它包装它的内在孩子的内容。
标签: android android-recyclerview android-scrollview android-wrap-content