Reputation: 1501
I have an activity with collapsing toolbar and a nested scroll view with a FrameLayout
that I place the fragments in it. Initially, I place in it a FragmentA
with a CardView .
Works great. When I click a button though I replace that FragmentB
with another one containing a RecyclerView .
When I add the FragmentB
I cant scroll to the bottom of the list.
Host Activity Layout:
<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:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlwaysCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">
.........
......
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<!-- the layout which will be the content of the activity (which will be hosted inside the drawer (NOT the list of the drawer)) -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
</FrameLayout>
</android.support.v4.widget.NestedScrollView>
FragmentB Layout:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/contentView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_users"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
layout="@layout/view_progress"
/>
<include
layout="@layout/view_retry"
/>
<!--</LinearLayout>-->
</android.support.v4.widget.SwipeRefreshLayout>
Upvotes: 13
Views: 4731
Reputation: 1062
Two things:
First of all you don't have to embed your fragment container in NestedScrollView
if you want a scrolling behavior in your activity.
Put FrameLayout
directly into Coordinator layout with layout_behavior
attribute in it, then simply put any fragment with scrolling View (and it don't have to have layout_behavior attr).
So in your example you should have to fragments:
FragmentA
that has layout with CardView inside NestedScrollView
FragmentB
with RecyclerView inside SwipeRefreshLayout
Other problem is that you put more then one child in SwipeRefreshLayout
, and as stated in documentation it should have only one direct child. source
Upvotes: 2
Reputation: 5788
Already answered! Two scrollable elements (such as RecycleView and NestedScrollView in your question) can't work together.
Edit your Activity layout.
<ParentLayout>
.......
<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:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlwaysCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">
.........
......
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
//THIS FRAGMENT WILL BE REPLACED!
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
</FrameLayout>
.......
</ParentLayout>
And than by default, in first run of this activity - replaced FrameLayout above - to your first fragment with NestedScrollView (You need to create new Fragment for replacing) and after click replacing to Fragment in your Question.
Upvotes: 0
Reputation: 50
i think this is scrollevent problem,customview extends ListView or RecycleView. this is my sol:
public class RewriteListView extends ListView {
public RewriteListView(Context context) {
super(context);
}
public RewriteListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public RewriteListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
be happy :)
Upvotes: 0
Reputation: 1736
You put RecyclerView
inside the NestedScrollView
.
I think better solution is to have NestedScrollView
or RecyclerView
but not both, because RecyclerView
is already implementing NestedScrollingChild
.
I have similar layout in my app. I did the same - put RecyclerView to FrameLayout and then inside the NestedScrollView. It's stop to work correctly. Without NestedScrollView everything works fine.
Upvotes: 5