java等间距固定大小按钮
我有这个xml文档。我想让这些93×93像素的按钮图像等间距排列。目前,重量设置使他们伸展并相互拥抱,因此没有空间。但如果我将“权重”设置为0,它们会彼此拥抱,但会占据屏幕的一半
顺便说一下,这是用于景观定位的
<LinearLayout 安卓:id="@+id/LinearLayout" 安卓:layout_height="wrap_content"
安卓:layout_width="fill_parent">
<Button
安卓:background="@drawable/a"
安卓:layout_height="93px"
安卓:id="@+id/a"
安卓:layout_width="93px"
安卓:layout_weight="1"
安卓:layout_marginLeft="20dip"
安卓:layout_marginTop="30dip"/>
<Button
安卓:background="@drawable/b"
安卓:layout_height="93px"
安卓:id="@+id/b"
安卓:layout_width="93px"
安卓:layout_weight="1"
安卓:layout_marginTop="30dip"/>
<Button
安卓:background="@drawable/c"
安卓:layout_height="93px"
安卓:id="@+id/c"
安卓:layout_weight="1"
安卓:layout_width="93px"
安卓:layout_marginTop="30dip"/>
<Button
安卓:background="@drawable/d"
安卓:layout_height="93px"
安卓:id="@+id/d"
安卓:layout_width="93px"
安卓:layout_weight="1"
安卓:layout_marginRight="20dip"
安卓:layout_marginTop="30dip" />
</LinearLayout>
a
# 1 楼答案
试试这个:
# 2 楼答案
我尝试将你当前的线性布局更新为以下内容,并使用了方形等距按钮——但它们不适合我的模拟器屏幕。所以在我的例子中,是你在左边和右边设置的边距把它们挤进去了
你考虑过两排吗?我用TableLayout为一款声卡应用做了类似的事情。虽然现在我倾向于更多地使用RelativeLayout。这是表格代码
# 3 楼答案
只需在任意一个按钮上设置左边距或右边距
# 4 楼答案
LinearLayout
没有“等间距”的固有概念。您可能会考虑使用为“仪表板”设计的布局,例如https://gist.github.com/882650。# 5 楼答案
解决办法很简单
您必须将每个按钮保持在单独的线性布局中,并将每个线性布局的权重保持为1。现在,无论分辨率或方向如何,按钮的间距都是相等的
例: