
我想让所有9个按钮自动调整大小,关于设备的宽度和高度,并将它们均匀地放在3 * 3网格中.但我现在只能为他们的尺码设定数字.
任何人都可以告诉我如何让他们使用父母的身高和宽度并计算他们的大小?
此外,我现在使用网格布局.这是我应该用于tic-tac-toe游戏的最佳布局吗?
谢谢.
解决方法 使用linearLayouts与androID:weightSum和androID:layout_weight编辑
示例:
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical" androID:weightSum="3" > <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="0dp" androID:layout_weight="1" androID:orIEntation="horizontal" androID:weightSum="3" > <Imagebutton androID:layout_wIDth="0dp" androID:layout_height="fill_parent" androID:layout_weight="1" androID:src="@drawable/ic_launcher" /> <Imagebutton androID:layout_wIDth="0dp" androID:layout_height="fill_parent" androID:layout_weight="1" androID:src="@drawable/ic_launcher" /> <Imagebutton androID:layout_wIDth="0dp" androID:layout_height="fill_parent" androID:layout_weight="1" androID:src="@drawable/ic_launcher" /> </linearLayout> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="0dp" androID:layout_weight="1" androID:orIEntation="horizontal" androID:weightSum="3" > <Imagebutton androID:layout_wIDth="0dp" androID:layout_height="fill_parent" androID:layout_weight="1" androID:src="@drawable/ic_launcher" /> <Imagebutton androID:layout_wIDth="0dp" androID:layout_height="fill_parent" androID:layout_weight="1" androID:src="@drawable/ic_launcher" /> <Imagebutton androID:layout_wIDth="0dp" androID:layout_height="fill_parent" androID:layout_weight="1" androID:src="@drawable/ic_launcher" /> </linearLayout> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="0dp" androID:layout_weight="1" androID:orIEntation="horizontal" androID:weightSum="3" > <Imagebutton androID:layout_wIDth="0dp" androID:layout_height="fill_parent" androID:layout_weight="1" androID:src="@drawable/ic_launcher" /> <Imagebutton androID:layout_wIDth="0dp" androID:layout_height="fill_parent" androID:layout_weight="1" androID:src="@drawable/ic_launcher" /> <Imagebutton androID:layout_wIDth="0dp" androID:layout_height="fill_parent" androID:layout_weight="1" androID:src="@drawable/ic_launcher" /> </linearLayout></linearLayout>总结
以上是内存溢出为你收集整理的如何在android xml布局中将3个按钮放入3行?全部内容,希望文章能够帮你解决如何在android xml布局中将3个按钮放入3行?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)