Java RecyclerView height wrap#U内容不';在NestedScrollView中不工作
因此,我有高度wrap_content的recyclerView,因为我理解这意味着每当我向它添加或删除项目时,recyclerView应该展开或折叠,但由于某种原因,在NestedScrollView中,当我向它添加新对象时,它的行为与此不同,它和以前一样大,有什么问题吗? 尝试添加 android:fillViewport=“true” 但据我所知,并没有任何反应,这可能是因为当它的子项发生变化时,RecyclerView并没有得到更新,因为当我重新启动应用程序时,它会折叠或扩展到适当的大小 以下是我的xml:Java RecyclerView height wrap#U内容不';在NestedScrollView中不工作,java,android,xml,android-recyclerview,android-nestedscrollview,Java,Android,Xml,Android Recyclerview,Android Nestedscrollview,因此,我有高度wrap_content的recyclerView,因为我理解这意味着每当我向它添加或删除项目时,recyclerView应该展开或折叠,但由于某种原因,在NestedScrollView中,当我向它添加新对象时,它的行为与此不同,它和以前一样大,有什么问题吗? 尝试添加 android:fillViewport=“true” 但据我所知,并没有任何反应,这可能是因为当它的子项发生变化时,RecyclerView并没有得到更新,因为当我重新启动应用程序时,它会折叠或扩展到适当的大小
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/icons"
android:orientation="vertical">
<LinearLayout
android:id="@+id/main_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical">
<include layout="@layout/toolbar" />
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested"
android:fillViewport="true"
android:scrollbars="none"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/empty_group_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TextView
android:id="@+id/empty_text_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="@string/no_group_first"
android:textColor="@color/secondary_text"
android:textSize="17sp" />
<ImageView
android:id="@+id/add_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/empty_text_first"
android:src="@drawable/ic_add_group_gry" />
<TextView
android:id="@+id/empty_text_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/add_icon"
android:text="@string/no_group_second"
android:textColor="@color/secondary_text"
android:textSize="17sp" />
</RelativeLayout>
</RelativeLayout>
<TextView
android:textSize="14sp"
android:layout_marginStart="6dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Favorite groups"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/favorite_group_list"
android:nestedScrollingEnabled="true"
android:layout_width="match_parent"
android:layout_height="156dp"
android:layout_gravity="center"
android:background="@color/icons"
android:padding="6dp">
</android.support.v7.widget.RecyclerView>
<TextView
android:textSize="14sp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_marginStart="6dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Groups"/>
<android.support.v7.widget.RecyclerView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/group_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:nestedScrollingEnabled="false"
android:padding="6dp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/add_new_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:src="@drawable/ic_playlist_add_48px"
app:behavior_autoHide="true"
app:layout_anchor="@id/main_holder"
app:layout_anchorGravity="bottom|right|end" />
Hi kosas在设置布局时为回收者视图提供包装内容 经理:请跟我来
linearLayoutManager = new LinearLayoutManager(getActivity()) {
@Override
public boolean canScrollVertically() {
return false;
}
};
问题可能与适配器的布局有关。确保在适配器的布局
高度上放置一些固定值或包装内容。如果它是match\u parent
它将不会像预期的那样工作,因为每一行都将填充第二个RecyclerView的所有RecyclerView
,我使用的是GridLayoutManager,我对第一个没有问题如果你没有将垂直滚动设置为false,滚动将不会平滑OK,但我的问题是滚动不平滑,但当recyclerView的大小增加时,nestedScrollView并没有扩展