我有tablayout viewpager,裏面ViewPager I'hv它正在創造一個RecyclerView片段,Recyclerview與刷卡左/右
在RecyclerVIew魚子項目我已經創建的水平滾動型,用於獲取向左掃/正確的運動,
基本上我想向左滑動該行只有75%的屏幕,然後顯示滑動式視圖,
我也用的RecyclerView
ItemTouchHelper
但刷卡完整的行(100%刷卡行),
我知道有創建刷卡左,右的手勢在谷歌可用庫,
但所有這些工作不正常,因爲當我們在刷卡項目recyclerview,有時倒是去ViewPager因此頁面獲得刷卡我不想即,
所以,我用HorizontalScrollView,但問題是,我無法檢測HorizontalScrollView的觸摸聽者內刷卡方向,
其實我們想一定量後自動滾動,如果滾動上HorizontalScrollView
,
下面是我嘗試過的代碼。
holder.scrollContainer.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int scroll1st = 0;
int scroll2nd = 0;
if(event.getAction() == MotionEvent.ACTION_DOWN){
scroll1st = holder.scrollContainer.getScrollX();
Log.d("SCROLL", "Scroll down callded: amt is: " + holder.scrollContainer.getScrollX());
mDataSet.get(position).isFirstSwipe = false;
} else if (event.getAction() == MotionEvent.ACTION_UP){
scroll2nd = holder.scrollContainer.getScrollX();
Log.d("SCROLL", "Scroll up callded: amt is: " + holder.scrollContainer.getScrollX());
}
Log.d("SCROLL", "max scroll amount: " + holder.scrollContainer.getMaxScrollAmount());
if(event.getAction() == MotionEvent.ACTION_UP){
if(scroll2nd > scroll1st && (scroll2nd - scroll1st) > 50){
holder.scrollContainer.postDelayed(new Runnable() {
public void run() {
holder.scrollContainer.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
}, 100L);
mDataSet.get(position).isFirstSwipe = true;
} else if (scroll1st > scroll2nd && (scroll1st - scroll2nd) > 50){
holder.scrollContainer.postDelayed(new Runnable() {
public void run() {
holder.scrollContainer.fullScroll(HorizontalScrollView.FOCUS_LEFT);
}
}, 100L);
mDataSet.get(position).isFirstSwipe = true;
}
}
v.onTouchEvent(event);
return true;
}
});
基本上ACTION.DOWN事件不被調用每次所以不能得出不刷卡方向
我得到的所有滾動事件轉義Action.DOWN,但有時Action.DOWN也來 –
嘗試與ACTION.SCROLL,看看你是否可以趕上它。 –
基本上我需要X1和X2,所以我可以決定滾動directon –