NestedScrollview中具有HasFixedSize的Recyclerview wrap_content不显示项目

时间:2019-06-10 13:11:52

标签: android android-recyclerview

作为标题。我正在使用Recyclerview显示我的物品。但是我需要在Recyclerview(具有wrap_content高度)上方的更多视图,因此我决定使用NestedScroll视图。但是令人毛骨悚然的是,当我设置Recyclerview.setHasFixedSize(true)时,这些项目不会显示出来。当我设置Recyclerview.setHasFixedSize(false)时。他们出现。如何设置Recyclerview.setHasFixedSize(true)并且项目仍然显示?

这是XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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_height="match_parent"
    android:orientation="vertical"
    android:layout_width="match_parent">

    <include layout="@layout/appbar_layout"/>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:scrollbars="none"
        android:fillViewport="true"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_height="match_parent">


            <include layout="@layout/searchbar_layout"/>

            <android.support.v7.widget.RecyclerView

                android:layout_width="match_parent"
                android:scrollbars="none"
                android:nestedScrollingEnabled="false"
                android:background="@color/white"
                android:layout_height="wrap_content" />

        </LinearLayout>

    </android.support.v4.widget.NestedScrollView>


</LinearLayout>

这是商品行XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:weightSum="1"
    android:gravity="center_vertical"
    android:background="@color/white"
    android:layout_height="wrap_content">

        <de.hdodenhof.circleimageview.CircleImageView
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center_vertical"


            />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAllCaps="false"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:textColor="@color/black"
            android:textSize="@dimen/row_main_infor_text_size"
            android:lines="1"
            android:maxLines="1"
            android:ellipsize="end"
            android:textStyle="bold"

            android:gravity="center_vertical"
            />


        <TextView
            android:layout_width="80dp"
            android:layout_height="30dp"
            android:layout_gravity="center"
            android:background="@drawable/lightgrey_radius_20_bg"
            android:gravity="center"

            android:textAllCaps="true"

            android:textColor="@color/black"
            android:textSize="@dimen/button_text_size" />

</LinearLayout>


这是JAVA代码:

RecyclerView.LayoutManager layoutManager_VERTICAL = new LinearLayoutManager(ForwardMessage.this, LinearLayoutManager.VERTICAL, false);

        rv_all_friends = (RecyclerView) findViewById(R.id.rv_all_friends);
        rv_all_friends.setLayoutManager(layoutManager_VERTICAL);
        rv_all_friends.setHasFixedSize(true);
        ((SimpleItemAnimator) rv_all_friends.getItemAnimator()).setSupportsChangeAnimations(false);
        rv_all_friends.setAdapter(mAllFriends_Adapter);

0 个答案:

没有答案