【问题标题】:How to make a 4x4 grid of imagebuttons in android?如何在android中制作一个4x4的imagebuttons网格?
【发布时间】:2016-09-05 20:11:37
【问题描述】:

我花了几个星期四处寻找如何做到这一点,并遇到了诸如 thisthis 之类的东西,但它似乎已经有几年了/我无法理解如何应用它满足我的需要。

我想要的只是让我的图像按钮在屏幕上的 4x4 网格中,并且每个按钮启动一个类似的活动,但具有不同的数据。 (它是一种闪存卡类型的东西,但每张卡片都有不同的文字)。看起来这应该很简单,但是这是我的第一个android应用,也是我第一次直接接触xml和java,我感觉我迷路了。

有什么好的方法来实现这个?我并不特别喜欢做一个gridView,并且对任何有效的东西都持开放态度。

有点像这样:

【问题讨论】:

  • 究竟坚持哪一部分?制作网格(看起来已经完成了)?如果它正在创建活动,那么只需有一个活动并通过Intent 传递数据以了解按下了哪个按钮并相应地在下一个活动中执行您的功能。
  • 看起来已经完成 b/c “屏幕截图”是在 Adob​​e Illustrator 中完成的 :)

标签: android gridview android-imagebutton


【解决方案1】:

您可以使用 GridView。以下 Android 文档链接包含有关如何使用它的示例和详细信息。

Android 文档: https://developer.android.com/guide/topics/ui/layout/gridview.html

https://developer.android.com/reference/android/widget/GridView.html

【讨论】:

  • 哦,酷!我什至不知道它会起作用!我会试试这个,如果它有效,那么它会节省我一点!
【解决方案2】:

您可以使用 TableLayout 来实现它。下面的例子。显然您可以将按钮更改为 ImageButtons。

      <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:stretchColumns="*">
        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1">
            <Button
                android:id="@+id/button1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />
            <Button
                android:id="@+id/button2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />
        </TableRow>
        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1">
            <Button
                android:id="@+id/button3"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />
            <Button
                android:id="@+id/button4"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />
        </TableRow>
     </TableLayout>

【讨论】:

    猜你喜欢
    • 2021-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-22
    • 2021-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多