Android: network relationship graph

走远了吗. 提交于 2019-12-25 04:58:17

问题


I'll first explain what I'm trying to achieve and later on explain my current approach to solving it. I'm thankful for any useful input even if it would mean to start from scratch. I'll add more code or explanation if needed.

This is going to be a part of a bigger Android application. This part should display all nodes within a prior selected network and the relationships between the nodes all in one scrollable view/layout. The relationships should be pictured by arrows between the nodes, showing which nodes each node could 'hear' during a certain interval. The nodes sadly have to be clickable, because you have to able to set some options for other parts of the app within that view already. The actual data (nodes, neighbourhood relationships) should finally be returned via a webservice from a database, but this is not yet entirely relevant apart from the fact that the amount of nodes isn't static.

My current approach to this is to create GridView fill it with a custom ButtonAdapter, that way I can use a non-static amount of custom (transparent) buttons.

GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ButtonAdapter(this));

I have created methods that can draw arrows on a Bitmap and I can also easily set it as the GridView's background by converting it to Drawable.

protected Bitmap drawArrow(float startX, float startY, float endX, float endY, Bitmap bitmap) {
....
}

Drawable d = new BitmapDrawable(bitmap);
gridview.setBackgroundDrawable(d);

My issue with that approach is, that I'd need to know the exact size of the GridView for the Bitmap and the position of the buttons or alternatively the total height and width, that 1 button would use. Due to creating it within the onCreate I don't get the actual sizes at this point though. Is there a solution to this problem?

And even if that'd work I'm not sure just yet whether I can set the background in a way that it would scroll 1:1 with the GridView instead of getting scaled.


回答1:


Solved with a custom SurfaceView utilizing a custom thread and an extra class for each button which are simply drawn together with the lines between them on the surface. Scrolling had to be individually implemented as well.



来源:https://stackoverflow.com/questions/11225735/android-network-relationship-graph

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