gpt4 book ai didi

android - 在 viewpager 内平移的 achartengine

转载 作者:搜寻专家 更新时间:2023-11-01 08:55:27 26 4
gpt4 key购买 nike

我在 android.support.v4.view.ViewPager 中有一个 achartengine GraphicalView 图表。

我希望我的图表在用户将手指拖到图表上时平移,但现在事件在一个小的拖动 Action 后被 ViewPager 捕获。

我希望能够让用户平移到图表的末尾,然后让 ViewPager 切换页面。作为替代方案,我想至少阻止 ViewPager 捕获图表内的拖动运动。

有什么想法吗?

最佳答案

这是我的解决方案。

它允许用户在图表中有数据时四处拖动图表。之后,拖动事件被 ViewPager 捕获。

就像我说的,关键是这个解决方案是 requestDisallowInterceptTouchEvent功能。

public class ParameterGraphicalView extends org.achartengine.GraphicalView {

// stores the data model size
private int mDataSize = 0;
// stores the first X position in the dataset
private long mDataStartX = 0;
// stores the last X position in the dataset
private long mDataEndX = 0;

// the ViewPager
private ViewParent mViewPager;
//(...)
@Override
public boolean onTouchEvent(MotionEvent event) {

// save the position of the first touch so we can determine whether the user is dragging
// left or right
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mFirstTouchX = event.getX();
}

// when mViewPager.requestDisallowInterceptTouchEvent(true), the viewpager does not
// intercept the events, and the drag events (pan, pinch) are caught by the GraphicalView

// we want to keep the ViewPager from intercepting the event if:
// 1- there are 2 or more touches, i.e. the pinch gesture
// 2- the user is dragging to the left but there is no data to show to the right
// 3- the user is dragging to the right but there is no data to show to the left
if (event.getPointerCount() > 1
|| (event.getX() < mFirstTouchX && mDataSize > 0 && mRenderer.getXAxisMax() < mDataEndX)
|| (event.getX() > mFirstTouchX && mData.size() > 0 && mRenderer.getXAxisMin() > mDataStartX)) {
mViewPager.requestDisallowInterceptTouchEvent(true);
}
else {
mViewPager.requestDisallowInterceptTouchEvent(false);
}

return super.onTouchEvent(event);
}
}

关于android - 在 viewpager 内平移的 achartengine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19359516/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com