Reputation: 16211
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
Upvotes: 4
Views: 5829
Reputation: 36045
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);
Upvotes: 2