在Android中使EditText和Button具有相同的高度
我的 LinearLayout
中有一个 EditText
和一个 Button
,我想将它们紧密地对齐在一起,这样它们看起来似乎属于在一起(edittext + micButton用于语音输入)。
现在它们的高度不一样,而且对齐得不太好(Button
似乎比 EditText
低一点)。我知道我可以应用像 -5dp
这样的负边距来使它们靠得更近,但是是否有更好的方法来做到这一点?
将它们设置在特定的容器/布局中,以便它们自动具有相同的高度并且它们之间没有边距?
I have an EditText
and a Button
in my LinearLayout
and I want to align them closely together so they see seem to belong together (edittext + micButton for speech input).
Now they don't have the same height and they aren't really aligned well (Button
seems to be a little lower than the EditText
). I know I can apply a negative margin like -5dp
to make them come closer together, but is there perhaps a better way to do this?
Set them in a specific container/layout so that they will automatically have the same height and no margin between them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用相对布局,您可以根据另一个视图的大小来拉伸视图,而无需知道另一个视图的确切大小。
这是代码:
检查此链接以减少视图之间的空间:
https://groups.google.com/forum/?fromgroups# !topic/android-developers/RNfAxbqbTIk
Using relative layout you can stretch a view depending upon another views size without knowing the exact size of the other view.
Here is the code :
Check this link for reducing space between views :
https://groups.google.com/forum/?fromgroups#!topic/android-developers/RNfAxbqbTIk
嗯,不知道为什么人们这么在意桌子。由于这两个视图都在 LinearLayout 内(大概的orientation = Horizontal),因此此命令应在布局中居中:
注意:由于 EditText 和 Button 的文本方向可能略有不同,因此您可能需要执行一些操作调整(通过更改边距或填充)以使文本正确对齐。
Hmm, don't know why people bother so much with tables. Since the both Views are within a LinearLayout (presumable orientation=Horizontal), this command should center both within the layout:
Note: Since EditTexts and Buttons may orient their text slightly differently, you may have to do some tweaking (by changing margins or padding) to get the text to align properly.
我希望这个解决方案对您的场景有所帮助...这是代码..
I hope this solution might help for your scenario...Here is the code..
@Daniel 这里你可以使用布局权重和权重总和
@ Daniel Here You can use layout weight and weight sum
Android 尝试自动调整文本的所有内容,而不是按钮本身。
我花了很长时间才终于弄清楚。这真的很简单。应该修复它。
或者如果它们是连续的..将按钮附加到表格行,然后。
Android tries to automatically level everything off of the text and not the buttons themselves.
Took me forever to finally figure it out. Its really simple. Should fix it.
or if they are in a row.. attach the buttons to a table row, then.