Android- 如何在一行中创建 4 个方形按钮,并在它们上面放置图标?
Android- How to create 4 square buttons in one row with icons on top of them?
我正在尝试创建一个应用程序,它在一行中有 4 个方形按钮,这些按钮顶部有一个图标。哪种方法最好?如图所示,我正在尝试做这样的事情
谢谢
您尝试过Table布局吗?尽管您可以使用任何布局,但我建议您坚持使用一个父布局,例如相对布局,然后使用多个子布局来管理 UI 个元素。
将可绘制图像设置在 @mipmap/ic_launcher_round
的位置
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="4sp"
android:orientation="horizontal"
android:weightSum="4">
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4sp"
android:layout_weight="1"
android:src="@mipmap/ic_launcher_round" />
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4sp"
android:layout_weight="1"
android:src="@mipmap/ic_launcher_round" />
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4sp"
android:layout_weight="1"
android:src="@mipmap/ic_launcher_round" />
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4sp"
android:layout_weight="1"
android:src="@mipmap/ic_launcher_round" />
</LinearLayout>
</LinearLayout>
感谢大家的解答。我发布的图像是在 photoshop 上编辑的。现在我在 android 工作室使用线性布局
我正在尝试创建一个应用程序,它在一行中有 4 个方形按钮,这些按钮顶部有一个图标。哪种方法最好?如图所示,我正在尝试做这样的事情
谢谢
您尝试过Table布局吗?尽管您可以使用任何布局,但我建议您坚持使用一个父布局,例如相对布局,然后使用多个子布局来管理 UI 个元素。
将可绘制图像设置在 @mipmap/ic_launcher_round
的位置<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="4sp"
android:orientation="horizontal"
android:weightSum="4">
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4sp"
android:layout_weight="1"
android:src="@mipmap/ic_launcher_round" />
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4sp"
android:layout_weight="1"
android:src="@mipmap/ic_launcher_round" />
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4sp"
android:layout_weight="1"
android:src="@mipmap/ic_launcher_round" />
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4sp"
android:layout_weight="1"
android:src="@mipmap/ic_launcher_round" />
</LinearLayout>
</LinearLayout>
感谢大家的解答。我发布的图像是在 photoshop 上编辑的。现在我在 android 工作室使用线性布局