【发布时间】:2012-08-09 19:10:31
【问题描述】:
目前我正在尝试使用以下代码设置我以编程方式创建的视图的位置:
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中的位置
【问题讨论】:
-
问题需要更好地概述,你想达到什么目的?也许一个简单的布局图会有所帮助。如果您想将某些内容与屏幕底部对齐,请考虑使用等价的 alignParentBottom="true" 的相对布局
-
查看 [this answer][1] ,直截了当 [1]:stackoverflow.com/questions/12195768/…
标签: android android-layout android-view android-compatibility