android – 在RelativeLayout中在运行时对齐视图

android – 在RelativeLayout中在运行时对齐视图,第1张

概述如何在运行时在相对布局中添加视图,以使其在父级的顶部对齐.假设我在单击按钮时添加了EditText.现在,这个EditText应该以EditText位于Button之上. 这是我正在做的一个例子. button = new Button(this); //here I am just checking if the button can come above the EditText b 如何在运行时在相对布局中添加视图,以使其在父级的顶部对齐.假设我在单击按钮时添加了EditText.现在,这个EditText应该以EditText位于button之上.

这是我正在做的一个例子.

button = new button(this);  //here I am just checking if the button can come above the EditText    button.setText("I am a button");      params.addRule(relativeLayout.BELOW,editText.getID());      params.addRule(relativeLayout.AliGN_PARENT_ABOVE);      relativeLayout.addVIEw(button);

我根本无法进行对齐.
任何线索都非常感谢.
提前致谢.

解决方法 您需要使用relativeLayout.addVIEw的重载,它将LayoutParams作为第二个参数

button = new button(this);  //here I am just checking if the button can come above the EditText    button.setText("I am a button");      params.addRule(relativeLayout.BELOW,editText.getID());      params.addRule(relativeLayout.AliGN_PARENT_ABOVE);      relativeLayout.addVIEw(button,params);

addView method

总结

以上是内存溢出为你收集整理的android – 在RelativeLayout中在运行时对齐视图全部内容,希望文章能够帮你解决android – 在RelativeLayout中在运行时对齐视图所遇到的程序开发问题。

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

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

原文地址: https://outofmemory.cn/web/1121771.html

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

发表评论

登录后才能评论

评论列表(0条)

保存