android - 带有 Fragment 和 RelativeLayout(包含 RecyclerView)的嵌套 ScrollView 不滚动
问题描述
我有一个包含一个 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>
有人可以告诉我有什么问题吗?
解决方案
尝试这个 :
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布局文件:
<com.core.views.VerticalScrollview
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:overScrollMode="never">
//YOUR VIEWS
</VerticalScrollview>
推荐阅读
- excel - 如何根据下拉选择返回指向另一个工作表的超链接
- python - 给定一个单词和该单词的每个字母的数字,如何创建每个组合的完整树?
- bash - 在 ESXI 主机上执行 SSH 远程 ash 脚本时遇到问题
- python - 绘制由 3D numpy 数组表示的 3d 体积数据
- scala - 复合流会形成循环吗?
- c# - VS 2019 和 Visual Studio 安装程序中的 .NET Core 缺少单元测试功能?
- python - 基于 anaconda 为 python 创建 exe,包括 fbprophet
- ios - 当提示打开另一个应用程序时,如何处理用户单击取消
- javascript - 图表没有从它从 Jquery 收到的值更新
- python - 文本锚不起作用。(使用canvas.create_window)