我应该采取什么方法来制作数个网格?

发布于 2025-01-08 03:54:27 字数 457 浏览 0 评论 0原文

我正在为 Android 创建一个 Kakuro 游戏,它主要由一个大网格组成,其中仅包含根据图案的黑色和白色方块。我决定使用从 Button 扩展的自定义类来表示黑色和白色方块。

但问题是,我无法弄清楚使用和/或扩展什么来表示包含正方形(包含按钮)的网格。它应该具有以下行为:

  • 应该能够沿着 x 轴和 y 轴容纳 Button
  • 应该可以两种方式滚动,因为网格肯定会超出设备的屏幕尺寸。
  • 不应该对内存占用太苛刻。

因此,经过一番思考,我决定创建一个扩展 View 的自定义类。但我不确切知道要重写哪些方法才能获得我想要的行为。

那么谁能告诉我应该重写哪些方法才能获得我需要的行为? (其行为有点类似于扫雷)。

或者我可以使用其他更简单/更快的方法吗?

提前致谢!

I'm creating a Kakuro game for Android and it mainly consists of a large grid which contains only black and white squares according to a pattern. I have decided to use a custom class extended from Button to represent black and white squares.

But the problem is, I can't figure out what to use and/or extend to represent the square-containing (Button-containing) grid. It should have the following behavior:

  • Should be able to house Buttons along both x- and y-axes.
  • Should be scrollable in both ways as the grid will most definitely exceed the device's screen size.
  • Should not be too hard on the memory footprint.

So after some thinking, I have decided to create a custom class that extends View. But I don't know exactly which methods to override to obtain the behavior I want.

So can anyone please tell me which methods I should override to obtain the behavior I need? (The behavior is somewhat similar to that of Minesweeper).

Or is there any other easier/faster method I can use?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何时共饮酒 2025-01-15 03:54:27

如果它是您想要的网格,我推荐 GridView

在二维滚动网格中显示项目的视图。物品
网格中的内容来自与此视图关联的 ListAdapter。

GridView 教程:http://developer.android .com/resources/tutorials/views/hello-gridview.html

if it is a grid you want, I recommend the GridView.

A view that shows items in two-dimensional scrolling grid. The items
in the grid come from the ListAdapter associated with this view.

GridView tutorial: http://developer.android.com/resources/tutorials/views/hello-gridview.html

云淡风轻 2025-01-15 03:54:27

Extending the GridView seems more suitable for your need: http://developer.android.com/resources/tutorials/views/hello-gridview.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文