Setting the viewing position in the 7th level API

I'm currently 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()); 

PROBLEM

The error I am getting is that I cannot use the setLeft and setTop in api levels less than 11.

QUESTION

How to programmatically set view position in API level < 11

+4
source share
1 answer

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

 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); 
+2
source

All Articles