Posted by custom View for the map
public class MetroMapView extends ScrollView { Context ctx; List<Station> list; RelativeLayout v; LayoutInflater inflater; View station; DisplayMetrics metrics; HorizontalScrollView xScroller; List<View> stations; public MetroMapView(Context ctx, AttributeSet attrs) { super(ctx, attrs); this.ctx = ctx; inflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); metrics = new DisplayMetrics(); ((GameActivity)ctx).getWindowManager().getDefaultDisplay().getMetrics(metrics); v = new RelativeLayout(ctx); v.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); v.setMinimumHeight(metrics.heightPixels * 2); v.setMinimumWidth(metrics.widthPixels * 3); xScroller = new HorizontalScrollView(ctx); xScroller.setScrollContainer(true); xScroller.addView(v); addView(xScroller); setScrollContainer(true); setVerticalScrollBarEnabled(true); setHorizontalScrollBarEnabled(true); } void setElements(ArrayList<Station> list) throws Exception { this.list = list; for(Station s : list) { View station = inflater.inflate(R.layout.station_view, v, true); station.setId(View.generateViewId()); station.setX(s.getX()); station.setY(s.getY()); v.addView(station); } } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); } } In ScrollView sits HorizontalScrollView , and in it - RelativeLayout , in which I place the View . In the setElements method setElements I pass in a collection of stations. Each station has x and y coordinates. That's how I do in activity
List<Station> stations = new ArrayList<>(); Station lt = new Station(0,0); Station rt = new Station(metrics.widthPixels * 3 - 50,0); Station lb = new Station(0,metrics.heightPixels * 2 - 50); Station rb = new Station(metrics.widthPixels * 3 - 50, metrics.heightPixels * 2 - 50); stations.add(lt); stations.add(rt); stations.add(lb); stations.add(rb); try { map.setElements(stations); } catch (Exception e) { Log.d("$", e.toString()); } As a result, I get such a log
The specified child already has a parent. You must call removeView () on the child's parent first.
But I do not understand what it means already busy. I find solutions where I need to delete the View , but I don’t need it, they should stay