1.开始一直反应不过来一个问题:RecycleView不是自带滚动效果吗?为啥子条目还不能全部滚动,显示出来呢?

意识到:只有当RecycleView 适配器中条目数量特别多,才可以滚动。

然而自己的布局,只是一个TextView内容特别多。

2.所以网上看到看到下面的帖子里面的布局。自己修改后,完成。

https://stackoverflow.com/questions/43753083/recycleview-using-view-holder-able-to-scroll-inside

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"> <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbarStyle="outsideOverlay"
android:paddingBottom="28dp" />
</android.support.v4.widget.SwipeRefreshLayout> </android.support.v4.widget.NestedScrollView> </LinearLayout>

二、存在的问题:记得是:左右滑动加上后,就无法上下滚动了。

后来切换了,采用的

public class GallerySnapHelper extends SnapHelper {
private static final float INVALID_DISTANCE = 1f;
private static final float MILLISECONDS_PER_INCH = 40f;
private OrientationHelper mHorizontalHelper;
private RecyclerView mRecyclerView; private OnSwipeListener mListener; public OnSwipeListener getmListener() {
return mListener;
} public void setmListener(OnSwipeListener mListener) {
this.mListener = mListener;
} @Override
public void attachToRecyclerView(@Nullable RecyclerView recyclerView) throws IllegalStateException {
mRecyclerView = recyclerView;
super.attachToRecyclerView(recyclerView);
} @Override
public int[] calculateDistanceToFinalSnap(@NonNull RecyclerView.LayoutManager layoutManager, @NonNull View targetView) {
int[] out = new int[2];
if (layoutManager.canScrollHorizontally()) {
out[0] = distanceToStart(targetView, getHorizontalHelper(layoutManager));
} else {
out[0] = 0;
}
return out;
} private int distanceToStart(View targetView, OrientationHelper helper) {
return helper.getDecoratedStart(targetView) - helper.getStartAfterPadding();
} @Nullable
protected LinearSmoothScroller createSnapScroller(final RecyclerView.LayoutManager layoutManager) {
if (!(layoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)) {
return null;
}
return new LinearSmoothScroller(mRecyclerView.getContext()) {
@Override
protected void onTargetFound(View targetView, RecyclerView.State state, Action action) {
int[] snapDistances = calculateDistanceToFinalSnap(mRecyclerView.getLayoutManager(), targetView);
final int dx = snapDistances[0];
final int dy = snapDistances[1];
final int time = calculateTimeForDeceleration(Math.max(Math.abs(dx), Math.abs(dy)));
if (time > 0) {
action.update(dx, dy, time, mDecelerateInterpolator);
}
} @Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
}
};
} @Override
public int findTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY) {
LogUtil.d(MainActivity.TAG,"---velocityX:::"+velocityX+"----velocityY:::"+velocityY);
if(velocityX>0) {
if (!(layoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)) {
LogUtil.d(MainActivity.TAG, "-!(layoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)---RecyclerView.NO_POSITION--");
return RecyclerView.NO_POSITION;
} final int itemCount = layoutManager.getItemCount();
if (itemCount == 0) {
LogUtil.d(MainActivity.TAG, "-itemCount=0---RecyclerView.NO_POSITION--");
return RecyclerView.NO_POSITION;
} final View currentView = findSnapView(layoutManager);
if (currentView == null) {
LogUtil.d(MainActivity.TAG, "-currentView = null---RecyclerView.NO_POSITION--");
return RecyclerView.NO_POSITION;
} final int currentPosition = layoutManager.getPosition(currentView);
if (currentPosition == RecyclerView.NO_POSITION) {
LogUtil.d(MainActivity.TAG, "-currentPosition = RecyclerView.NO_POSITION---RecyclerView.NO_POSITION--");
return RecyclerView.NO_POSITION;
} RecyclerView.SmoothScroller.ScrollVectorProvider vectorProvider =
(RecyclerView.SmoothScroller.ScrollVectorProvider) layoutManager;
// deltaJumps sign comes from the velocity which may not match the order of children in
// the LayoutManager. To overcome this, we ask for a vector from the LayoutManager to
// get the direction.
PointF vectorForEnd = vectorProvider.computeScrollVectorForPosition(itemCount - 1);
if (vectorForEnd == null) {
LogUtil.d(MainActivity.TAG, "-vectorForEnd = null---RecyclerView.NO_POSITION--");
// cannot get a vector for the given position.
return RecyclerView.NO_POSITION;
} //在松手之后,列表最多只能滚多一屏的item数
int deltaThreshold = layoutManager.getWidth() / getHorizontalHelper(layoutManager).getDecoratedMeasurement(currentView); int hDeltaJump;
if (layoutManager.canScrollHorizontally()) {
LogUtil.d(MainActivity.TAG, "----layoutManager.canScrollHorizontally()-----" + layoutManager.canScrollHorizontally());
hDeltaJump = estimateNextPositionDiffForFling(layoutManager,
getHorizontalHelper(layoutManager), velocityX, 0); if (hDeltaJump > deltaThreshold) {
hDeltaJump = deltaThreshold;
}
if (hDeltaJump < -deltaThreshold) {
hDeltaJump = -deltaThreshold;
} if (vectorForEnd.x < 0) {
hDeltaJump = -hDeltaJump;
}
} else {
Log.d(TAG, "----hDeltaJump = 0--layoutManager.canScrollHorizontally()---" + layoutManager.canScrollHorizontally());
hDeltaJump = 0;
} if (mListener != null) {
mListener.onSwipedClear();
} if (hDeltaJump == 0) {
Log.d(TAG, "----if (hDeltaJump == 0)---true--");
return RecyclerView.NO_POSITION;
} int targetPos = currentPosition + hDeltaJump;
if (targetPos < 0) {
targetPos = 0;
}
if (targetPos >= itemCount) {
targetPos = itemCount - 1;
}
Log.d(TAG, "----targetPos-----" + targetPos);
return targetPos;
}else {
//当判断是右滑时,不处理。
Log.d(TAG, "-----“-1”-----");
return -1;
}
} @Override
public View findSnapView(RecyclerView.LayoutManager layoutManager) {
return findStartView(layoutManager, getHorizontalHelper(layoutManager));
} private View findStartView(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) {
if (layoutManager instanceof LinearLayoutManager) { LogUtil.d(MainActivity.TAG, "-findStartView---layoutManager instanceof LinearLayoutManager--");
int firstChildPosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
if (firstChildPosition == RecyclerView.NO_POSITION) {
LogUtil.d(MainActivity.TAG, "-findStartView---firstChildPosition == RecyclerView.NO_POSITION--");
return null;
} /*
注释该段代码,否则不能正常滑动
if (((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1) {
///0
LogUtil.d(MainActivity.TAG, "-findStartView---layoutManager.getItemCount() - 1::::"+(layoutManager.getItemCount() - 1));
LogUtil.d(MainActivity.TAG, "-findStartView---((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1--");
return null;
}*/ View firstChildView = layoutManager.findViewByPosition(firstChildPosition);
if (helper.getDecoratedEnd(firstChildView) >= helper.getDecoratedMeasurement(firstChildView) / 2 && helper.getDecoratedEnd(firstChildView) > 0) {
return firstChildView;
} else {
return layoutManager.findViewByPosition(firstChildPosition + 1);
}
} else {
LogUtil.d(MainActivity.TAG, "-findStartView--!!!!!--layoutManager instanceof LinearLayoutManager--");
return null;
}
} private int estimateNextPositionDiffForFling(RecyclerView.LayoutManager layoutManager,
OrientationHelper helper, int velocityX, int velocityY) {
int[] distances = calculateScrollDistance(velocityX, velocityY);
float distancePerChild = computeDistancePerChild(layoutManager, helper);
if (distancePerChild <= 0) {
return 0;
}
int distance = distances[0];
if (distance > 0) {
return (int) Math.floor(distance / distancePerChild);
} else {
return (int) Math.ceil(distance / distancePerChild);
}
} private float computeDistancePerChild(RecyclerView.LayoutManager layoutManager,
OrientationHelper helper) {
View minPosView = null;
View maxPosView = null;
int minPos = Integer.MAX_VALUE;
int maxPos = Integer.MIN_VALUE;
int childCount = layoutManager.getChildCount();
if (childCount == 0) {
return INVALID_DISTANCE;
} for (int i = 0; i < childCount; i++) {
View child = layoutManager.getChildAt(i);
final int pos = layoutManager.getPosition(child);
if (pos == RecyclerView.NO_POSITION) {
continue;
}
if (pos < minPos) {
minPos = pos;
minPosView = child;
}
if (pos > maxPos) {
maxPos = pos;
maxPosView = child;
}
}
if (minPosView == null || maxPosView == null) {
return INVALID_DISTANCE;
}
int start = Math.min(helper.getDecoratedStart(minPosView),
helper.getDecoratedStart(maxPosView));
int end = Math.max(helper.getDecoratedEnd(minPosView),
helper.getDecoratedEnd(maxPosView));
int distance = end - start;
if (distance == 0) {
return INVALID_DISTANCE;
}
return 1f * distance / ((maxPos - minPos) + 1);
} private OrientationHelper getHorizontalHelper(RecyclerView.LayoutManager layoutManager) {
if (mHorizontalHelper == null) {
mHorizontalHelper = OrientationHelper.createHorizontalHelper(layoutManager);
}
return mHorizontalHelper;
} }
public interface OnSwipeListener<T>{
/**
* 卡片还在滑动时回调
*
* @param viewHolder 该滑动卡片的viewHolder
* @param ratio 滑动进度的比例
* @param direction 卡片滑动的方向,CardConfig.SWIPING_LEFT 为向左滑,CardConfig.SWIPING_RIGHT 为向右滑,
* CardConfig.SWIPING_NONE 为不偏左也不偏右
*/
void onSwiping(RecyclerView.ViewHolder viewHolder, float ratio, int direction); /**
* 卡片完全滑出时回调
*
* @param viewHolder 该滑出卡片的viewHolder
* @param t 该滑出卡片的数据
* @param direction 卡片滑出的方向,CardConfig.SWIPED_LEFT 为左边滑出;CardConfig.SWIPED_RIGHT 为右边滑出
*/
void onSwiped(RecyclerView.ViewHolder viewHolder, T t, int direction); /**
* 所有的卡片全部滑出时回调
*/
void onSwipedClear(); }
Activity 界面代码
GallerySnapHelper mGallerySnapHelper = new GallerySnapHelper();
mGallerySnapHelper.setmListener(new OnSwipeListener() {
@Override
public void onSwiping(RecyclerView.ViewHolder viewHolder, float ratio, int direction) { } @Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, Object o, int direction) { } @Override
public void onSwipedClear() {
Log.d(TAG,"-----onSwipedClear----");
giRecyclerView.postDelayed(new Runnable() {
@Override
public void run() {
groupIdeaHttp.getJtidea(URLCODE_GET_GROUP_IDEA,oaapi.getBASE_URL3());
giRecyclerView.getAdapter().notifyDataSetChanged();
}
}, 100L);
}
}); mGallerySnapHelper.attachToRecyclerView(giRecyclerView);
giRecyclerView.setAdapter(groupIdeaAdapter);

RecycleView 使用自定义CardLayouManager内容无法滚动问题的更多相关文章

  1. jquery鼠标移动div内容上下左右滚动

    jquery鼠标移动div内容上下左右滚动 点击这里查看效果:http://keleyi.com/keleyi/phtml/jqtexiao/9.htm <!DOCTYPE html PUBLI ...

  2. 第九篇 :微信公众平台开发实战Java版之如何实现自定义分享内容

    第一部分:微信JS-SDK介绍 微信JS-SDK是微信公众平台面向网页开发者提供的基于微信内的网页开发工具包. 通过使用微信JS-SDK,网页开发者可借助微信高效地使用拍照.选图.语音.位置等手机系统 ...

  3. 微信js接口自定义分享内容

    最近客户有个要求,需要给网页添加微信分享功能,当然指的是用微信自带浏览器的时候,希望用户在最后一页点击分享的时候是分享的首页.曾经无意中看到过微信公众开发者平台提供了js接口,所以试着做了做,果然,跌 ...

  4. jQuery自定义插件--banner图滚动

    前言 jQuery是一个功能强大的库,提供了开发JavaScript项目所需的所有核心函数.很多时候我们使用jQuery的原因就是因为其使用插件的功能,然而,有时候我们还是需要使用自定义代码来扩展这些 ...

  5. 简单实现弹出弹框页面背景半透明灰,弹框内容可滚动原页面内容不可滚动的效果(JQuery)

    弹出弹框 效果展示 实现原理 html结构比较简单,即: <div>遮罩层 <div>弹框</div> </div> 先写覆盖显示窗口的遮罩层div.b ...

  6. CALayer 知识:创建带阴影效果的圆角图片图层和创建自定义绘画内容图层

    效果如下: KMLayerDelegate.h #import <UIKit/UIKit.h> @interface KMLayerDelegate : NSObject @end KML ...

  7. 滚动条ScrollViewer防止滚动时按内容跳跃式滚动的设置

    原文:滚动条ScrollViewer防止滚动时按内容跳跃式滚动的设置 属性中将CanContentScroll设置为False,滚动时就不会跳了,会连续的滚动

  8. js实现页面元素随着内容的滚动而滚动

      CreateTime--2017年9月4日16:55:06 Author:Marydon js实现页面元素随着内容的滚动而滚动 分析: CSS样式,使用绝对定位确定好页面元素在屏幕的位置(如:正中 ...

  9. webbrowser内容滚动(javascript内容无缝滚动)

    一 使用webbrowser现有方法 引用:https://blog.csdn.net/xiaokailele/article/details/48392673 public partial clas ...

随机推荐

  1. [python] pyCharm 右击出现run unittest 解决办法

    最近在使用 pyCharm 的时候发现一个情况,右击时出现 "unittests for ...",这时候如果继续点击 run ,可能会出现错误. 看到网上的介绍说,原因是程序方法 ...

  2. nginx, supervisor, celery

      资料: supervisor和nginx使用 1 .supervisor 管理进程工具 2 .nginx 反向代理, 负载均衡 安装nginx $ sudo apt-get update $ su ...

  3. 55.纯 CSS 创作一个太阳、地球、月亮的运转模型

    原文地址:https://segmentfault.com/a/1190000015313341 感想:主要运用边框.伪元素.动画. HTML code: <div class="co ...

  4. 《算法》第四章部分程序 part 4

    ▶ 书中第四章部分程序,加上自己补充的代码,图的深度优先遍历 ● 无向图的深度优先遍历,有向 / 无向图代码仅若干方法名不同,包括递归和非递归版本,去掉了顶点有效性的检查 package packag ...

  5. Impala SQL 使用小记

    1.  impala端创建的表,DROP. hive会自动同步到. 但是通过hive DROP时,数据还会在,只是表的元数据没有了. 所以完全DROP表,需要impala端的DROP 2. impal ...

  6. Timer TimerTask schedule scheduleAtFixedRate

    jdk 自带的 timer 框架是有缺陷的, 其功能简单,而且有时候它的api 不好理解. import java.util.Date; import java.util.Timer; import ...

  7. java -version 问题 : C:\ProgramData\Oracle\Java\javapath;

    我把 JAVA_HOME 从8改成了 7 , 为什么还是 显示的8啊 ! E:\sv0\jars>java -version java version "1.8.0_111" ...

  8. 《锋利的JQuery》中的动画效果:

    说实话,虽然这本书已经很老了,老到什么程度呢,这本书以JQuery1.9以前的版本写就的,toggle()方法的(func1,func2,...)这个切换事件的功能已经被删去了 但是这本书还是挺8错的 ...

  9. <基础> PHP 进阶之 类型转换

    引用官方的解释 PHP 在变量定义中不需要(或不支持)明确的类型定义:变量类型是根据使用该变量的上下文所决定的.也就是说,如果把一个 string 值赋给变量$var,$var 就成了一个 strin ...

  10. ubuntu防火墙命令初探

    1.防火墙的状态与开关 1)$sudo ufw status  //查看防火墙的状态及当前的设置规则 2)$sudo ufw enable //开启防火墙 3)$sudo ufw disable // ...