我有一个FrameLayout活动,我在其中添加或替换多个片段。该活动使用CollapsingToolbarLayout。
在第一个场景中,我添加了一个带有NestedScrollView,LinearLayout,CardView和TextViews的片段。一切正常,工具栏的滚动和折叠/展开。
在第二种情况下,我使用SwipeRefreshLayout和RecyclerView向FrameLayout添加一个片段,但问题是当我向上滚动工具栏时不会崩溃。
在此视频中,您可以看到问题:LINK
活动布局:
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="340dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
................
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/printerModels"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end"
style="@style/FabStyle"/>
第一个场景片段布局:
<android:android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:paddingTop="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="5dip"
android:layout_margin="15dp"
android:layout_marginBottom="50dp"
app:cardCornerRadius="3dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="@dimen/model_detail_card_view_margin">
..........
..........
//Several textviews here
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android:android.support.v4.widget.NestedScrollView>
第二种情景布局:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_users"
android:scrollbars="vertical"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<include
layout="@layout/view_progress"
/>
<include
layout="@layout/view_retry"
/>
<!--</LinearLayout>-->
</android.support.v4.widget.SwipeRefreshLayout>
答案 0 :(得分:2)
在xml中禁用RecyclerView的嵌套滚动
android:nestedScrollingEnabled="false"
答案 1 :(得分:1)
您的坐标布局:
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="340dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
................
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
//This <include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/printerModels"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end"
style="@style/FabStyle"/>
content_main.xml
<android:android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</FrameLayout>
</android:android.support.v4.widget.NestedScrollView>