好的,这是一个困扰多年的问题。我希望在 android 屏幕的顶部水平放置 5 个按钮。在任何手机上,这些按钮的宽度都必须是屏幕宽度的 20%(以便它们彼此并排没有间隙)。
我只是无法弄清楚XML。我怎样才能做到这一点?有没有人有任何想法/样本?谢谢!
好的,这是一个困扰多年的问题。我希望在 android 屏幕的顶部水平放置 5 个按钮。在任何手机上,这些按钮的宽度都必须是屏幕宽度的 20%(以便它们彼此并排没有间隙)。
我只是无法弄清楚XML。我怎样才能做到这一点?有没有人有任何想法/样本?谢谢!
对于按钮行,使用屏幕全宽的水平线性布局,将所有按钮放入其中,并给按钮布局宽度为 0 且布局权重 > 0:
<LinearLayout
. . .
android:layout_width="match_parent"
android:orientation="horizontal"
/>
<Button
. . .
android:layout_width="0"
android:layout_weight="1"
/>
<Button
. . .
android:layout_width="0"
android:layout_weight="1"
/>
. . .
</LinearLayout>
<LinearLayout
...
layout_width = "match_parent"
layout_height = "wrap_content" />
<Button
....
layout_width = "0dp"
layout_height = "wrap_content"
layout_weight = 1 />
<Button
....
layout_width = "0dp"
layout_height = "wrap_content"
layout_weight = 1 />
<Button
....
layout_width = "0dp"
layout_height = "wrap_content"
layout_weight = 1 />
<Button
....
layout_width = "0dp"
layout_height = "wrap_content"
layout_weight = 1 />
<Button
....
layout_width = "0dp"
layout_height = "wrap_content"
layout_weight = 1 />
</LinearLayout>