【发布时间】:2017-10-05 12:02:49
【问题描述】:
所以我的 recyclerView 高度为 wrap_content,据我了解,这意味着每当我向其中添加或删除项目时 recyclerView 应该展开和折叠,但由于某种原因,在 NestedScrollView 中,当我向其中添加新对象时,它的行为并不像那样,它的大小保持不变,因为任何想法可能有什么问题? 尝试添加
android:fillViewport="true"
但据我了解,没有反应可能是因为 RecyclerView 在其子项更改时没有更新,因为当我重新启动应用程序时,它会折叠或展开到适当的大小。
这是我的 xml:
<?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" />
【问题讨论】:
标签: java android xml android-recyclerview android-nestedscrollview