如果RecyclerView的ViewHolder包含另一个水平的RecyclerView,我的CollapsingToolbarLayout就不能和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/circlebd_rootview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="256dip"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/header"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.4" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/circleinfo_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/recyclerbg"
android:fillViewport="true"
android:layout_marginBottom="?attr/actionBarSize"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/></android.support.design.widget.CoordinatorLayout>
这是我的ViewHodler
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dip"
android:background="@color/gray_light"
android:paddingBottom="1dp">
<RelativeLayout
android:id="@id/con_item_r1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/contentitem_top"
android:paddingBottom="10dip">
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@id/con_item_recyclerview"
android:layout_width="match_parent"
android:layout_height="@dimen/showimg_height"
android:layout_below="@id/con_item_r1"/>
ViewHolder的RecyclerView是水平的,而主活动的RecyclerView是垂直的。如果我把ViewHolder的RecyclerView改为View,CollapsingToolbarLayout就可以了。我的问题是如何使用ViewHolder的RecyclerView,同时让CollapsingToolbarLayout工作。
RecyclerView recyclerView = someView.findViewById(R.id.con_item_recyclerview);
recyclerView.setNestedScrollingEnabled(false);
这个可以用
我有一个和你非常相似的问题,我是这样解决的。
你也可以在xml布局文件中通过指定以下属性进行设置。
android:nestedScrollingEnabled="false"