目前我正在尝试使用以下代码设置以编程方式创建的视图的位置:
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());
问题
我得到的错误是我无法在小于11的api级别使用setLeft
和setTop
属性。
问题
如何在API level < 11
答案 0 :(得分:2)
您好像已经在创建自定义视图了,因此您可以覆盖onLayout()
并在所需的布局上调用View#layout(int left, int top, int right, int bottom)
。
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);