0
我想创建一个带有NestedScrollView的RecyclerView,但RecyclerView不会显示。嵌套的RecyclerView不会显示
这是我的XML布局:
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.yarkoni.anybody.activities.OffersActivity"
tools:showIn="@layout/activity_offers">
<!-- A RecyclerView with some commonly used attributes -->
<android.support.v7.widget.RecyclerView
android:id="@+id/offerContent_recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_red_dark"
android:scrollbars="vertical" />
</android.support.v4.widget.NestedScrollView>
这是我的活动:
final LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
layoutManager.setAutoMeasureEnabled(false);
offersRecyclerView.setLayoutManager(layoutManager);
ArrayList<Offer> offerList = new ArrayList<>();
offerList.add(new Offer("Lorem"));
offerList.add(new Offer("Lorem"));
OffersAdapter offersAdapter = new OffersAdapter(offerList);
offersRecyclerView.setAdapter(offersAdapter);
offersRecyclerView.setNestedScrollingEnabled(false);
调试此类问题的最佳方法是首先为RecyclerView指定一个固定高度,确保它首先正确显示。也很好奇为什么你在ScrollView中有一个匹配/匹配RecyclerView,看起来像是其中一个是无关紧要的。 – wblaschko