Android 安卓-如何在一行中创建4个正方形按钮,并在其顶部添加图标?

Android 安卓-如何在一行中创建4个正方形按钮,并在其顶部添加图标?,android,button,tiles,Android,Button,Tiles,我正在尝试创建一个应用程序,其中一行有4个方形按钮,按钮顶部有一个图标。哪种方法是最好的?我试着做一些像图中所示的事情 谢谢您尝试过表格布局吗?尽管您可以使用任何布局,但我建议您坚持使用一个父布局,如相对布局,然后使用多个子布局来管理UI元素。将您的可绘制图像设置为@mipmap/ic\u launcher\u round <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://sc

我正在尝试创建一个应用程序,其中一行有4个方形按钮,按钮顶部有一个图标。哪种方法是最好的?我试着做一些像图中所示的事情


谢谢

您尝试过表格布局吗?尽管您可以使用任何布局,但我建议您坚持使用一个父布局,如相对布局,然后使用多个子布局来管理UI元素。

将您的可绘制图像设置为@mipmap/ic\u launcher\u 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上编辑的

没有最好的办法。到目前为止你试过什么?到底是什么问题?把纽扣做成正方形?把它们排成一行?在它们上面放置图标?我的2美分插件:一个只有一行图像按钮的GridView。你可以使用权重为其中的4个按钮均分行。你能发布你的代码吗。到目前为止你做了什么?我建议不要使用“子布局”,因为嵌套布局不利于性能。真的。但有时当您不想使用约束布局时,您必须使用此类方法。或者您可以使用GridView,正如我在前面的评论中所建议的那样。