我正在使用RecyclerView
显示项目,但是当我以编程方式将其高度设置为wrap_content
和setHasFixedSize(true)
时,这些项目不会显示。但是当我更改为setHasFixedSize(false)
时,它可以正常工作。我希望RecyclerView
用NestedScrollView和其他视图滚动(不希望RecyclerView
滚动本身)。我该怎么办?
这是布局代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".Fragments.Fragment_Community"
android:layout_height="match_parent"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView android:layout_width="wrap_content"
android:text="Header 1"
android:textColor="@color/grey"
android:textStyle="bold"
android:layout_margin="10dp"
android:textAllCaps="true"
android:background="@color/white"
android:textSize="@dimen/messages_text_size"
android:gravity="center_vertical"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" />
<TextView android:layout_width="match_parent"
android:text="Header 2"
android:textColor="@color/grey"
android:textStyle="bold"
android:textAllCaps="true"
android:background="@color/white"
android:textSize="@dimen/messages_text_size"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:scrollbars="none"
android:background="@color/white"
android:focusable="false"
android:nestedScrollingEnabled="true"
android:layout_height="wrap_content"
android:id="@+id/rv_suggestions"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
这是java代码:
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
mSuggestions_Rv.setHasFixedSize(true);
mSuggestions_Rv.setLayoutManager(linearLayoutManager);
mSuggestions_Rv.setAdapter(mSuggestions_Adapter);