For some reason the position ( margin ) of the layout i have created is not set. the layout shows up at x=0 and y=0. What am I doing wrong?
smallPopup = new LinearLayout(this);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
p.setMargins(100, 100, 10, 10);
smallPopup.setLayoutParams(p);
smallPopup.setGravity(Gravity.CENTER_VERTICAL);
smallPopup.setHorizontalGravity(Gravity.CENTER_HORIZONTAL);
smallPopup.setBackgroundResource(R.drawable.map_small_popup_overlay);
smallPopup.setPadding(20, 10, 20, 10);
map.addView(smallPopup, p);
There are several types of LayoutParams, depending on the container of your view.
If you want to position an element inside a MapView you need to use MapView.LayoutParams, which does not support margin (because it does not extend MargingLayoutParams).
MapView.LayoutParams extends AbsoluteLayout.LayoutParams, which means you can directly set the x and y values: