![](/img/trans.png)
[英]Scrollview containing recyclerview and viewpager not scrolling
[英]Nested ScrollView with a Fragment and RelativeLayout (containing RecyclerView) not scrolling
我有一個包含一個 LinearLayout 的 NestedScrollView 布局。
這個 LinearLayout 包含一個 Fragment(FrameLayout 作為容器)和一個包含 RecyclerView 的 RelativeLayout。
問題是只有 RecyclerView 正在滾動並且項目在片段下方。
理想情況下,片段應該與 recyclerview 一起向上滾動。 我嘗試在 recyclerview 上設置 nestedScrollingEnabled = false 但這停止了所有滾動(即使對於 recyclerview 也是如此)。
這是布局:
<?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>
有人能告訴我出了什么問題嗎?
嘗試這個 :
垂直滾動視圖.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布局文件:
<com.core.views.VerticalScrollview
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:overScrollMode="never">
//YOUR VIEWS
</VerticalScrollview>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.