Android - Remove lines from path

人走茶凉 提交于 2019-12-12 04:08:34

问题


I need to make a realtime visual plot of some data much like the "heart beat" scope. Currently, I have data that comes in and I append a Path using lineTo(int, int). When the plot gets to the edge of the screen, I would like to either shift the data to the left to make room for the new data (preferred) or jump back to the left side of the screen and start erasing the beginning of the path with the new data.

I can get the data to move to the left using the offset(int, int) method, but as a large amount of data gets added this makes a path that is unnecessarily long when all that is needed is to display the most current data. I can't find a method to remove the first part of a path. What is an efficient way to rebuild the path with the oldest data removed?


回答1:


You cannot remove any Path (or parts of a Path) from an existing Path, you can only add, see Path, hence you must manage the parts on your own. To do so you split the path in seperate chunks

Path[] chunks = new Path[2]; //two chunks should be enough
Path currentPath;

private void reCreatePath(){
    currentPath = new Path(chunks[0]);
    currentPath.addPath(chunks[1]);
}

you can reCreate the path any time and and shift the content for the chunks

chunks[0] = chunks[1]; //moving chunks 1 -> chunks 0
chunks[1] = ... //add here your new Path

reCreatePath(); //makes a new Path using data from chunks


来源:https://stackoverflow.com/questions/37261428/android-remove-lines-from-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!