嵌套的RecyclerView不会显示

时间:2016-11-15 21:49:33

标签: android android-recyclerview

我正在尝试使用NestedScrollView创建一个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);

1 个答案:

答案 0 :(得分:0)

尝试给予recyclerview固定高度。