【发布时间】:2016-10-23 16:16:14
【问题描述】:
我正在尝试制作类似于this. 的布局 但我需要元素(图像)具有相等且完整的大小来创建它们之间的间距,而不是使用边距来分隔它们。
【问题讨论】:
我正在尝试制作类似于this. 的布局 但我需要元素(图像)具有相等且完整的大小来创建它们之间的间距,而不是使用边距来分隔它们。
【问题讨论】:
您可以使用android TableLayout 达到所需的结果。
Here 是 TableLayout 的开发者链接
【讨论】:
有时网格布局不是答案。尝试 3 种线性布局,这样很简单
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="#000000">
<Button
android:layout_height="60dp"
android:layout_width="match_parent"
android:background="@drawable/icon_you_should_know"
android:maxWidth="360dp"/>
<LinearLayout
android:layout_height="120dp"
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="top|center">
<Button
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:maxWidth="120dp"
android:background="@drawable/icon_wounded_demon"/>
<Button
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:maxWidth="120dp"
android:background="@drawable/icon_maze_desert"/>
<Button
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:maxWidth="120dp"
android:background="@drawable/icon_working_with_darkness"/>
</LinearLayout>
<LinearLayout
android:layout_height="120dp"
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="top|center">
<Button
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:maxWidth="120dp"
android:background="@drawable/icon_weak_spot"/>
<Button
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:maxWidth="120dp"
android:background="@drawable/icon_none"/>
<Button
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:maxWidth="120dp"
android:background="@drawable/icon_none"/>
</LinearLayout>
<LinearLayout
android:layout_height="120dp"
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="top|center">
<Button
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:maxWidth="120dp"
android:background="@drawable/icon_none"/>
<Button
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:maxWidth="120dp"
android:background="@drawable/icon_none"/>
<Button
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:maxWidth="120dp"
android:background="@drawable/icon_none"/>
</LinearLayout>
你也可以使用最大宽度和高度为每一行删除或添加一个按钮,不要忘记添加 layout_weight="1" 它的作品我希望它对你有用。
对于边距,您可以将图片放在更大的图片中,没有 PNG 格式的背景。
【讨论】: