Question

At the moment I am trying to set the position of my programmatically created view using the following code:

LayoutParams params = bottomBar.getLayoutParams();
params.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,(float) 5, getResources().getDisplayMetrics());
params.width = LayoutParams.MATCH_PARENT;
bottomBar.setLayoutParams(params);
bottomBar.setLeft(0);
bottomBar.setTop(this.getHeight()-bottomBar.getHeight());

THE PROBLEM

The error I get is that I cant use the setLeft and setTop properties in api levels less than 11.

THE QUESTION

How do I programmatically set the position of the view in API level < 11

Was it helpful?

Solution

It looks like you're already creating a custom view, so you would override onLayout() and call View#layout(int left, int top, int right, int bottom) on the layout you want.

final int left = 0;
final int top = getHeight() - bottomBar.getHeight();
final int right = left + bottomBar.getWidth();
final int bottom = top + bottomBar.getHeight();
bottomBar.layout(left, top, right, bottom);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top