Reputation: 11
I have a layout with NestedScrollView which contains one LinearLayout.
This LinearLayout contains a Fragment (FrameLayout as container) and a RelativeLayout containing RecyclerView.
The issue is that only the RecyclerView is scrolling and the items are going underneath the fragment.
Ideally, the fragment should scroll up along with recyclerview. I tried setting nestedScrollingEnabled = false on recyclerview but this stopped any scrolling all together (even for recyclerview).
Here's the layout:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:list="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical">
<FrameLayout
android:id="@+id/header_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical" />
<RelativeLayout
android:id="@+id/paginated_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/header_container"
android:paddingLeft="@dimen/card_margin"
android:paddingRight="@dimen/card_margin">
... swiperefreshlayout, recyclerview here.
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</layout>
Can somebody tell me what's wrong?
Upvotes: 1
Views: 639
Reputation: 1049
Try this :
VerticalScrollview.java
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ScrollView;
public class VerticalScrollview extends ScrollView {
public VerticalScrollview(Context context) {
super(context);
}
public VerticalScrollview(Context context, AttributeSet attrs) {
super(context, attrs);
}
public VerticalScrollview(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action)
{
case MotionEvent.ACTION_DOWN:
Log.i("VerticalScrollview", "onInterceptTouchEvent: DOWN super false" );
super.onTouchEvent(ev);
break;
case MotionEvent.ACTION_MOVE:
return false; // redirect MotionEvents to ourself
case MotionEvent.ACTION_CANCEL:
Log.i("VerticalScrollview", "onInterceptTouchEvent: CANCEL super false" );
super.onTouchEvent(ev);
break;
case MotionEvent.ACTION_UP:
Log.i("VerticalScrollview", "onInterceptTouchEvent: UP super false" );
return false;
default: Log.i("VerticalScrollview", "onInterceptTouchEvent: " + action ); break;
}
return false;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
super.onTouchEvent(ev);
Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction() );
return true;
}
}
xml layout file :
<com.core.views.VerticalScrollview
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:overScrollMode="never">
//YOUR VIEWS
</VerticalScrollview>
Upvotes: 0