Comments (7)
@zyonehangao 这个你解决了么
from cardswipelayout.
package com.yuqirong.cardswipeview;
import android.support.annotation.NonNull;
import android.support.v4.view.MotionEventCompat;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
/**
* @author yuqirong
*/
public class CardLayoutManager extends RecyclerView.LayoutManager {
private ItemTouchHelper mItemTouchHelper;
private float mPrevX;
private float mPrevY;
public CardLayoutManager(@NonNull RecyclerView recyclerView, @NonNull ItemTouchHelper itemTouchHelper) {
this.mItemTouchHelper = checkIsNull(itemTouchHelper);
recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent event) {
View child = rv.findChildViewUnder(event.getX(), event.getY());
if (child != null) {
RecyclerView.ViewHolder childViewHolder = rv.getChildViewHolder(child);
switch (MotionEventCompat.getActionMasked(event)) {
case MotionEvent.ACTION_DOWN:
mPrevX = event.getX();
mPrevY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
float eventX = event.getX();
float eventY = event.getY();
float xDiff = Math.abs(eventX - mPrevX);
float yDiff = Math.abs(eventY - mPrevY);
if (xDiff > yDiff) {
mItemTouchHelper.startSwipe(childViewHolder);
}
break;
default:
break;
}
}
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
});
}
private <T> T checkIsNull(T t) {
if (t == null) {
throw new NullPointerException();
}
return t;
}
@Override
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
@Override
public void onLayoutChildren(final RecyclerView.Recycler recycler, RecyclerView.State state) {
// 先把所有的View先从RecyclerView中detach掉,然后标记为"Scrap"状态,表示这些View处于可被重用状态(非显示中)。
// 实际就是把View放到了Recycler中的一个集合中。
detachAndScrapAttachedViews(recycler);
int itemCount = getItemCount();
for (int position = itemCount > CardConfig.DEFAULT_SHOW_ITEM ? CardConfig.DEFAULT_SHOW_ITEM : itemCount - 1; position >= 0; position--) {
// 遍历Recycler中保存的View取出来
final View view = recycler.getViewForPosition(position);
// 因为刚刚进行了detach操作,所以现在可以重新添加
addView(view);
// 通知测量view的margin值
measureChildWithMargins(view, 0, 0);
// 计算view实际大小,包括了ItemDecorator中设置的偏移量
int width = getDecoratedMeasuredWidth(view);
int height = getDecoratedMeasuredHeight(view);
int widthSpace = getWidth() - width;
int heightSpace = getHeight() - height;
// 指定了该View的显示区域,并将View显示上去,此时所有区域都用于显示View
layoutDecoratedWithMargins(view, widthSpace / 2, heightSpace / 2, widthSpace / 2 + width, heightSpace / 2 + height);
if (position == CardConfig.DEFAULT_SHOW_ITEM) {
view.setScaleX(1 - (position - 1) * CardConfig.DEFAULT_SCALE);
view.setScaleY(1 - (position - 1) * CardConfig.DEFAULT_SCALE);
view.setTranslationY((position - 1f) * view.getMeasuredHeight() / CardConfig.DEFAULT_TRANSLATE_Y);
} else if (position > 0) {
view.setScaleX(1 - position * CardConfig.DEFAULT_SCALE);
view.setScaleY(1 - position * CardConfig.DEFAULT_SCALE);
view.setTranslationY(position * view.getMeasuredHeight() / CardConfig.DEFAULT_TRANSLATE_Y);
}
}
}
}
from cardswipelayout.
怎么解决呢
from cardswipelayout.
@isayWu 对的 你把这个Layoutmanger拷贝过去直接用 就可以在item里面放recyclerview或者ScrollView了 这里面主要处理了滑动冲突
from cardswipelayout.
@isayWu 对的 你把这个Layoutmanger拷贝过去直接用 就可以在item里面放recyclerview或者ScrollView了 这里面主要处理了滑动冲突
thank you very mush
from cardswipelayout.
@isayWu 我又试了下是可以的 你检查下自己的环境哈 直接拷贝改下包名就行
from cardswipelayout.
@ansnail 是用这个 LayoutManager 直接覆盖原来的 CardLayoutManager 吗?貌似并没有什么用啊!
from cardswipelayout.
Related Issues (20)
- 关于剩余图片的计算,预加载
- 卡片的点击事件有冲突 HOT 3
- 重新写了一下CardSwipeLayout,完善了一下大佬的Demo HOT 1
- 滑动时经常出现两个item的情况
- How to swipe automatically. Whats the solution
- verticalScroll not working and swiping as well
- Card Swiping not worked
- viewHolder.itemView.setOnTouchListener(null); HOT 2
- 为啥会出现这个问题?
- 卡片点击事件有极大的问题 HOT 1
- 点击事件和卡片滑动有冲突 HOT 4
- 请问大神 数据加载和分页 HOT 1
- 10条内容,滑动到第11下 源码报错 数组越界
- v
- 可以监听支持加载更多吗?
- 是否可以控制滑动卡片是否会弹
- item上有子控件的点击事件与滑动有冲突。
- 能不能主动触发左滑动,和右滑动啊。点击一个button,直接执行左或者右滑,和探探一样 HOT 2
- single click
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cardswipelayout.