Android 自定义日历的网格布局
我正在开发一个需要我们自己的自定义日历视图的项目。我一直在努力找出解决这个问题的最佳方法。 我正在考虑可能使用一个主 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最近使用 TableLayout 创建了一个 Month 布局。
我考虑到你一个月需要 6x7 天才能处理所有可能的情况。 (该月的第一天是星期日,该月的最后一天是星期一等)
根据给定的日期(比如说 8 月 3 日),我计算要显示的第一天
,然后计算要显示的最后一天:
这给了我从
firstDate
到lastDate
的日期间隔,然后我以编程方式创建 6 个
TableRow
,其中有 7 天 - aTextView
或其他。如果您不想动态创建太多布局,则可以在 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
I then calculate the last day to be shown:
This gives me an interval of dates from
firstDate
tolastDate
Then I programaticly create 6
TableRow
's in which there are 7 days - aTextView
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 thelayout_weight
for theTextViews
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.
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.