Android项目-定义EditText大小
大家好,我正在尝试设置 EditText 的宽度。 我的目标是将 EditText 的长度设置为总屏幕的 1/2。
我写了这段代码:
RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainRelativeLayout);
int width = rl.getWidth();
int half = width/2;
EditText userName = (EditText) this.findViewById(R.id.userName);
userName.SET_SOMEHOW_THE_SIZE(half);
但我找不到设置宽度的工作方法:(
谢谢 马可
Hi guys I'm trying to set the width of an EditText.
My goal is to set the length of the EditText exactly 1/2 of the total screen.
I wrote this code:
RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainRelativeLayout);
int width = rl.getWidth();
int half = width/2;
EditText userName = (EditText) this.findViewById(R.id.userName);
userName.SET_SOMEHOW_THE_SIZE(half);
But i can't find a working method to set the width :(
Thanks
Marco
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在布局中做得更好,不要使用代码,
下面创建一个占据一半屏幕的 EditText 和一个占据另一半屏幕的 TextView,只需学习使用布局,它们应该让你得到你期望的结果
Better done within the layouts, don't use code
the following creates an EditText that takes half screen, and a TextView that takes the other half, just learn to play with the layouts, they should let you get the result you expect
Marco,
EditText
继承了TextView
。这意味着您可以使用继承的setWidth()
方法。Marco,
EditText
inheritsTextView
. This means you can use the inheritedsetWidth()
method.只要这样做:
Just do: