當用戶觸摸圖表並在用戶停止觸摸圖表時,可以禁用視圖頁面的滑動功能。首先定義一個Non-Swipable ViewPager
並讓您的查看尋呼機NonSwipable。
public class NonSwipableViewPager extends ViewPager {
private boolean canScroll = true;
public NonSwipableViewPager(Context context) {
super(context);
}
public NonSwipableViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setCanScroll(boolean canScroll) {
this.canScroll = canScroll;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
return canScroll && super.onTouchEvent(ev);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return canScroll && super.onInterceptTouchEvent(ev);
}
public boolean isCanScroll() {
return canScroll;
}
}
保留在公共變量中。 (與公共變量活動可能不會去最好的做法保持它。)
添加觸摸監聽到你的圖表,你的看法尋呼機禁止刷卡能力象下面這樣:
View yourChart = (YourChart) view.findViewById(R.id.your_chart);
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (activity.mainViewPager != null) {
activity.mainViewPager.setCanScroll(false);
}
break;
case MotionEvent.ACTION_UP:
if (activity.mainViewPager != null) {
activity.mainViewPager.setCanScroll(true);
}
break;
}
return false;
}
});
謝謝你,我會盡快檢查它,但我恐怕以前嘗試過類似的東西。 –
沒問題。但這是一個工作代碼。我在生產應用程序中使用它。 – savepopulation
不客氣。你接受了我的回答,但我無法得到獎勵積分(+50)你能幫忙嗎?謝謝。 – savepopulation