所以我有ViewPager
,ViewPager
包含两个标签,每个标签包含RecyclerView
,可以在每个RecyclerView
中添加和删除卡片。每个RecyclerView
都包含在Fragment
中。每个RecyclerView
使用ItemTouchHelper
来管理onSwiped()
个事件。 RecyclerView
内的卡片有几种行为:
我的问题是ViewPager
拦截了每个onSwiped()
的{{1}}方法,但是,每个RecyclerView
仍然可以正确接收垂直触摸事件。显然,这归结为触摸冲突问题。 RecyclerView
想要更改标签的水平触摸事件,ViewPager
想要水平触摸事件来刷卡。但是,RecyclerView
正在窃取所有触摸事件。我已在ViewPager
上禁用水平滑动(用户可以通过点击标签指示符来更改标签的唯一方式),但ViewPager
仍然无法接收任何水平触摸事件。
此处RecyclerView
已禁用滑动:
ViewPager
这是一个片段类:
public class NoSwipePager extends ViewPager {
public NoSwipePager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return false;
}
}
以下是管理@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.pit_tab, container, false);
container.getParent().requestDisallowInterceptTouchEvent(true);
RecyclerView rv = (RecyclerView) view.findViewById(R.id.movie_recycler_view);
return view;
}
:
RecyclerView
最后,这里应该调用的方法,但不是:
public EditManager(RecyclerView rv, Context act, EditListener listener, ArrayList<Element> elements, boolean editing, boolean pit) {
//rv = (RecyclerView) act.findViewById(R.id.movie_recycler_view);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(act);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
rv.setLayoutManager(linearLayoutManager);
((SimpleItemAnimator) rv.getItemAnimator()).setSupportsChangeAnimations(false);
if(elements != null) elementsAdapter = new ElementsAdapter(listener, act, new LinkedList<>(elements), editing);
else elementsAdapter = new ElementsAdapter(listener, act, null, editing);
rv.setAdapter(elementsAdapter);
ItemTouchHelper.Callback callback = new ElementTouchHelper(elementsAdapter);
ItemTouchHelper helper = new ItemTouchHelper(callback);
helper.attachToRecyclerView(rv);
}
答案 0 :(得分:1)
尝试将var states = ['Alabama', 'Alaska'];
var pop = [4863300, 741894];
var average = pop.reduce(function(sum, val){return sum + val;}) / pop.length;
console.log('Average: ' + average);
states.map(function(state, index) {
// Convert 2 arrays to an array of objects representing state info
return { name: state, population: pop[index] };
}).filter(function(stateInfo) {
console.log(stateInfo);
// Filter each item by returning true on items you want to include
return stateInfo.population < average;
}).forEach(function(stateInfo) {
// Lastly, loop through your results
console.log(stateInfo.name + ' has ' + stateInfo.population + ' people');
});
替换为:
NoSwipePager
我已成功使用此方法为public class NoSwipePager extends ViewPager {
public NoSwipePager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x,
int y) {
if (v instanceof RecyclerView) {
return(true);
}
return(super.canScroll(v, checkV, dx, x, y));
}
}
页面中的地图(用ViewPager
替换SurfaceView
)。我的猜测是你需要用更复杂的东西替换RecyclerView
测试(并根据你的应用自定义)。但我认为v instanceof RecyclerView
更有可能为您提供所需内容而非阻止canScroll()
。