我在布局中有3个按钮。我想要做的是增加按钮的大小,以便填满整个屏幕。我怎么能在XML文件中做到这一点?Android:如何更改在3个相同的按钮划分屏幕
回答
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_weight="1"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button2"
android:layout_weight="1"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button3"
android:layout_weight="1"/>
</LinearLayout>
您需要weightSum
按钮应该是垂直的,如果你使用'weight',那么你应该给'height = 0dip',如果vertical和width = 0dip是水平的。否则'重量'没有影响。 – Rustam 2014-10-07 18:38:28
严厉地说,你不需要'weightSum'。您只需通过分配权重即可达到相同的效果,而无需分配权重总和。我的猜测是,Android可以即时计算重量总和。 – 2014-10-08 06:21:49
您可以使用LinearLayout
的weight
属性。我会猜测并假设你想要垂直布局中的按钮。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button_1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:id="@+id/button_2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:id="@+id/button_3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
的Buttons
将始终填满屏幕,您可以与权重值发挥到修改他们的高度
你需要把按钮一的LinearLayout内,使用重量:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="3">
<Button
android:layout_height="0dip"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
<Button
android:layout_height="0dip"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
<Button
android:layout_height="0dip"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
他们想垂直按钮。 – Rustam 2014-10-07 18:32:12
这或Carlos J的回答比选定的答案更正确。 – 2014-10-08 06:23:47
- 1. 如何更改屏幕上的按钮
- 2. 在同一屏幕上编程3个或更多按钮
- 3. 如何在C中屏幕划分3个深度#
- 4. 屏幕上的按钮分页 - Android
- 5. 当点击按钮时更改屏幕
- 6. 当我在Kivy的另一个屏幕上按下按钮时,如何更改屏幕中的标签文本
- 7. 使用代表的Android Mono中的按钮屏幕更改
- 8. Android的按钮到另一个屏幕
- 9. 如何在屏幕分辨率更改后刷新屏幕?
- 10. Android;通过单击按钮更改布局/屏幕的背景
- 11. Android - 右侧屏幕按钮
- 12. android屏幕切换按钮
- 13. 如何使按钮适合相同数量的屏幕,并在Android应用程序相同的地方
- 14. Kivy - 如何更改不同屏幕中的屏幕过渡
- 15. Android的 - 用一个按钮来改变屏幕的亮度
- 16. 如何在android中使用整个屏幕作为按钮?
- 17. 如何在android主屏幕上添加一个按钮?
- 18. 如何更改Android主屏幕外观?
- 19. 如何根据屏幕尺寸更改按钮尺寸?
- 20. 如何根据屏幕设备更改按钮大小?
- 21. 五等分划分屏幕
- 22. 如何通过同一个按钮切换到多个屏幕
- 23. 在Swift中更改屏幕视图3
- 24. 如何更改Android内核中的屏幕分辨率
- 25. 如何更改我的Android应用程序的不同屏幕分辨率?
- 26. ANDROID屏幕方向更改
- 27. Android - 更改屏幕方向
- 28. 更改屏幕分辨率
- 29. 在android中修改锁定屏幕的主页按钮行为
- 30. Kivy - 按下ModalView中的按钮后更改屏幕
你尝试过什么吗? – Rustam 2014-10-07 18:21:51
显示您想要的一些示例UI。 – Rustam 2014-10-07 18:23:54
我想也许使按钮的高度取决于屏幕上,即。 android:layout_height =“(屏幕尺寸/ 3)”你知道我的意思是 – freeman292 2014-10-07 18:28:22