简体   繁体   English

如何使带有动态文本的按钮具有相同的大小和宽高比?

[英]How to make buttons, with dynamic text, the same size and width to height ratio?

I have a few buttons I want to display in a row in a decision tree. 我有几个按钮想在决策树中连续显示。 I'm trying to get the buttons in each row of the tree to be the same size. 我正在尝试使树的每一行中的按钮具有相同的大小。 But the buttons have different text. 但是按钮具有不同的文本。 Some have a couple words and some have a sentence. 有些有几个单词,有些有一个句子。 Is there a way I can get the buttons to all be the same size and all maintain the same width to height (4:3) ratio? 有什么办法可以使按钮的尺寸都相同,并且都保持相同的宽高比(4:3)?

I can get the heights the same using fill parent on the button heights while having the parent row layout_height set to wrap_content. 我可以在将父行layout_height设置为wrap_content的同时,使用填充父按钮高度来获得相同的高度。 How can I get the width of the buttons to be the same size while maintaining a 4:3 width to height ratio. 如何在保持4:3宽高比的同时将按钮的宽度设置为相同大小。 (The width to height ratio constraint is so I don't end up with really tall and thin buttons, which would look silly) (宽高比限制是这样,所以我不会得到真正又高又瘦的按钮,这看起来很愚蠢)

Anyone have any suggestions? 有人有什么建议吗?

Edit: 编辑:

I just saw this link which is kinda what I am looking for: Scaling layout with invariant aspect ratio in Android 我刚刚看到了这个链接,这正是我想要的: Android中纵横比不变的缩放布局

My problem with this is that it will inflate all the buttons and introduce a lot of empty space around the text inside. 我的问题是它将使所有按钮膨胀,并在其中的文本周围引入很多空白。

If I could find a way to incrementally increase the width or height (whichever is smaller) of the button and then resize it so it re-"wraps_content", then this could work. 如果我能找到一种方法来递增地增加按钮的宽度或高度(以较小者为准),然后调整其大小以使其重新“ wraps_content”,那么这可以工作。 Anyone know how to re-wrap the content? 有人知道如何重新包装内容吗?

如果您能够获得所有高度相同的高度,则可以对所有按钮使用android:layout_weight =“ 1”,然后将android:layout_width =“ 0dip”放进去,以便所有按钮的宽度相同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM