android – 以编程方式在API级别7中设置视图的位置

android – 以编程方式在API级别7中设置视图的位置,第1张

概述目前我正在尝试使用以下代码设置以编程方式创建的视图的位置: LayoutParams params = bottomBar.getLayoutParams();params.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,(float) 5, getResources().getDisplayMetrics 目前我正在尝试使用以下代码设置以编程方式创建的视图的位置:

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());

问题

我得到的错误是我不能在API级别小于11的情况下使用setleft和settop属性.

问题

如何以编程方式在API级别中设置视图的位置< 11

解决方法 看起来您已经在创建自定义视图,因此您将覆盖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);
总结

以上是内存溢出为你收集整理的android – 以编程方式在API级别7中设置视图的位置全部内容,希望文章能够帮你解决android – 以编程方式在API级别7中设置视图的位置所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1126658.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存