ListView with ArrayAdapter seems to be the only way of binding data to UI elements, and having access to rendering/rerendering strategies.
I want to absolutely position (x,y) UI elements (markers) above an image (map). If the data were to remain static, I would simply use ImageView within RelativeLayout within FrameLayout and set margins of the RelativeLayout to change the x and y position of the markers ("simply" is a gross understatement).
However, the data will change at intervals (the markers will move or change color), and I was hoping to leverage ArrayAdapter's notifyDataSetChanged() method to rerender the markers and reposition them.
Two questions (possibly unrelated to each other):
- Is ArrayAdapter with ListView the only way to bind (when data changes, UI elements rerender) data to UI elements in Android?
- Can I absolute position (think HTML/CSS) UI elements that are Items in a ListView?
EDIT I have something implemented now that "works" ...
// Excerpt from MyCustomAdapter.getView()
AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(50, 50);
convertView.setLayoutParams(layoutParams);
convertView.setY((float) y);
convertView.setX((float) x);
return convertView;
... I do not like this solution because the convertView views (markers on a map) jump around before they end up in the correct position (not index, but x, y position).
EDIT 2
int pullUpPullOver = 25; // half the height/width of the marker (to center it) ...
int offsetTop = 50 * position; // each item pushes the next down by 50 ...
int x = (location.getX() - pullUpPullOver);
int y = (location.getY() - pullUpPullOver) - offsetTop;
AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(50, 50);
convertView.setLayoutParams(layoutParams);
convertView.setTranslationX((float) x);
convertView.setTranslationY((float) y);
I don't like the sad hacks to do this. With HTML/CSS absolute and relative positioning in mind, is there a standard way for absolutely positioning elements (within a container view) in Android?