Android 自定义日历的网格布局

发布于 2024-12-08 06:25:12 字数 168 浏览 0 评论 0原文

我正在开发一个需要我们自己的自定义日历视图的项目。我一直在努力找出解决这个问题的最佳方法。 我正在考虑可能使用一个主 xml 文件来定义日历的基本布局,然后使用辅助 xml 文件,并将其作为对象数组嵌套到每天的日历的每个单元格中。

不确定这是否可行,或者这是否是解决此问题的最佳方法?

干杯

I'm working on a project that is going to require our own custom calendar view. I've been trying to figure out the best way to approach this.
I was considering possibly using a Master xml file that will define the basic layout of the calendar, and then use a secondary xml file, and nest it into each cell of the calendar for each day as an array of objects.

Not exactly sure if this is possible, or if this would be the best way to approach this problem?

Cheers

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

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

发布评论

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

评论(2

桃酥萝莉 2024-12-15 06:25:13

我最近使用 TableLayout 创建了一个 Month 布局。

我考虑到你一个月需要 6x7 天才能处理所有可能的情况。 (该月的第一天是星期日,该月的最后一天是星期一等)

根据给定的日期(比如说 8 月 3 日),我计算要显示的第一天

date = 3rd of August
firstDate = first day of month based on date
while( firstDate is not a monday )
   firstDate = present date

,然后计算要显示的最后一天:

lastDate = last day of month based on date
while( lastDate is not a Sunday )
   lastDay = following date

这给了我从 firstDatelastDate 的日期间隔

,然后我以编程方式创建 6 个 TableRow,其中有 7 天 - a TextView 或其他。如果您不想动态创建太多布局,则可以在 XML 文件中声明它。要记住的一件事是为 TextViews 设置 layout_weight ,以便它们都同样大/小,以创建一个漂亮的网格。

如果您需要的更像是日或周布局,那么挑战会更困难一些。

I recently created a Month layout, using TableLayout.

I took into consideration that you will need 6x7 days for a month to be able to handle every possible situation. (First day of the month being a sunday, last day of the month being a monday etc.)

Based on a given date (lets say 3rd of August) I calculate the first day to be shown

date = 3rd of August
firstDate = first day of month based on date
while( firstDate is not a monday )
   firstDate = present date

I then calculate the last day to be shown:

lastDate = last day of month based on date
while( lastDate is not a Sunday )
   lastDay = following date

This gives me an interval of dates from firstDate to lastDate

Then I programaticly create 6 TableRow's in which there are 7 days - a TextView or whatever. It could just be declared in an XML-file if you don't want to create too much layout on the fly. One thing to remember is to set the layout_weight for the TextViews so that they are all equally big/small to create a nice grid.

If what you need is more like a Day- or Weeklayout the challenge is a little tougher.

从来不烧饼 2024-12-15 06:25:13

Android 有一个实用程序可以进行所有数学计算以查找一个月中的天数。我想使用 gridview 与 android.util.MonthDisplayHelper< /strong> 应该可以。

Android has a util for doing all the math to find the days in a month. I guess using a gridview with android.util.MonthDisplayHelper should work.

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