【发布时间】:2016-03-02 12:28:00
【问题描述】:
我为我搜索答案,但没有找到适合我的工作答案。我在RecycleView 中查看我的项目时遇到了奇怪的错误:
我对 RecycleView 使用不同的视图。
我尝试使用此代码:
mLayoutManager.setAutoMeasureEnabled(true); // false doesn't work too
但这对我没有帮助。
UPD 1 我忘了注意这一点,抱歉。当我启动应用程序时,我没有错误(图像上的正常项目)但是当我开始滚动我的 RecycleView 时我遇到了问题)
UPD 2我回到compile 'com.android.support:recyclerview-v7:23.1.1',但它对我没有帮助(所以我用我的RecycleView 添加代码和xml,希望你能帮助我。
XML:
<android.support.v7.widget.RecyclerView
android:id="@+id/dashboard_recycle_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="none" />
和代码:
mRecyclerView = (RecyclerView) parent.findViewById(R.id.dashboard_recycle_view);
mLayoutManager = new LinearLayoutManager(getContext());
mLayoutManager.setAutoMeasureEnabled(false);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setHasFixedSize(false);
mRecyclerView.setAdapter(mRecycleAdapter);
【问题讨论】:
-
你的 recyclerview 的 layout_height 是多少?
-
@Amit Tiwari 我使用 wrap_content。如果我设置 match_parent 我在滚动之前遇到了这个问题。现在,使用 wrap_content 我开始滚动时遇到了这个问题
-
在早期版本的支持库中,wrap_content 存在一些问题,但是在 23.2 版本中,他们已经修复了 wrap_content 的回收器视图高度。因此,可能是,此版本中仍然存在错误。尝试将回收站视图的 layout_height 设置为某个静态值,例如 500dp,看看它是否正常工作。
-
@AmitTiwari 我无法设置固定大小,因为我在 RecycleView 中有不同的项目((((
-
您是否尝试在 mLayoutManager 上调用 setMeasurementCacheEnabled(false)?
标签: android android-recyclerview