Android 安卓按钮的宽度比例
我需要在一行中放置3个按钮。/使用LinearLayout/。 问题是当更改按钮上的文本时。宽度因“android:layout\u Width=“wrap\u content”而改变。我想确定thab按钮将按4:4:2的比例显示屏幕宽度。条款“wrap\u content”将打破这一点,但我不能使用确切的大小,因为我在设计时不知道设备屏幕宽度Android 安卓按钮的宽度比例,android,layout,Android,Layout,我需要在一行中放置3个按钮。/使用LinearLayout/。 问题是当更改按钮上的文本时。宽度因“android:layout\u Width=“wrap\u content”而改变。我想确定thab按钮将按4:4:2的比例显示屏幕宽度。条款“wrap\u content”将打破这一点,但我不能使用确切的大小,因为我在设计时不知道设备屏幕宽度 有人知道不使用代码就可以解决这个问题的简单方法吗?不要将其宽度设置为包裹内容。而是设置成比例的权重: <LinearLayout ...
有人知道不使用代码就可以解决这个问题的简单方法吗?不要将其宽度设置为包裹内容。而是设置成比例的权重:
<LinearLayout
...
layout_width = "match_parent"
layout_height = "wrap_content" />
<Button
....
layout_width = "0dp"
layout_height = "wrap_content"
layout_weight = 2 />
<Button
....
layout_width = "0dp"
layout_height = "wrap_content"
layout_weight = 2 />
<Button
....
layout_width = "0dp"
layout_height = "wrap_content"
layout_weight = 1 />
</LinearLayout>
尝试以下操作:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:weightSum="10" // SEE THIS IS 4+4+2 = 10
android:layout_centerHorizontal="true" >
<Button
android:layout_weight="4" // THIS IS 4
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:layout_weight="4" // THIS IS 4
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:layout_weight="2" // THIS IS 2
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</RelativeLayout>
应该是
android:layout\u weight=“4dp”对所有按钮使用layout\u weight=1这正是我所做的。因为按钮标签-系统调整了我的按钮大小和断开的比例。如果将宽度设置为0dp,那么你必须提供高度固定。你能提供高度固定吗?你是如何给出高度的?当文本长度的大小发生变化时,它不会变化吗?android:layout\u height=”当我设置height=“wrap\u content”并添加更大的文本时,“wrap\u content”,然后按钮的大小以及按钮的高度会有所不同。这在我的手机中运行良好。仍然需要尝试不同的设备。太好了!它也应该在其他设备中共享空间。