Why don't you just place the view at the bottom of the screen with ALIGN_PARENT_BOTTOM
and then apply a random padding?
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
view.setPadding(0, 0, 0, randomValue); // left, top, right, bottom
container.addView(view, params);
All this calculating with the view.getHeight()
is not good. Doing it like this works without you having to manage any of that yourself.