How can I create a weekly calendar view for an Android Honeycomb application?

自作多情 提交于 2019-11-29 23:13:02

I ended up following a similar approach to my original post. I created a scroll view with a linear layout inside of it. I then added seven relative layouts to the linear layout. Each of the relative layouts is one day. I made sure that the heights of these layouts were equal to the number of minutes in a day. This would make 1 hour = 60 minutes = 60 dp, which makes measuring the heights of events easier. For events, I created a custom view that can display the start and end time of the event, as well as the event's title. The events were added to the relative layouts with a layout_marginTop property, whose value equaled to the starting time of the event in minutes from the beginning of the day. This seemed to work just fine.

Here's a preview of what it ended up looking like:

Here's the XML layout: http://pastebin.com/jT4wQxeb

The code is too long to fit into the answer.

Note: calendar_zebra is simply a 60 * 24 = 1440dp high layout with 1 dp high horizontal Views with a solid gray background placed every 60dp. Each represents a marker for an hour of time.

1. Here is what I figure out from the source of Calendar

It creates a customized View(DayView for the agenda in a day) for the whole layout in your xml.

Then it draw the canvas using rectangle and text like what you can see in the app when the onDraw() is called.

The View implements OnClickListener and OnLongClickListener for the event. When you click on the canvas, it transfers your click position to the Event with corresponding Date and Time(so it calculated a lots of related size for event, margin, whole day event when the override onSizeChanged() is called), then starts the Activity if such Event exists, otherwise creates a new Event.

2.You need to create a Class extends View, say DayView, then you should add this into attrs.xml

<resources>
  <declare-styleable name="DayView">
  </declare-styleable>
</resources>

Then you can use it as a xml tag in layout with your package name. like here:

<xxxxxxx.DayView
       android:layout_height="wrap_content"
       android:layout_width="match_parent"
       android:id="@id/ui_schedule_dayview">

Here you can find the sample to do so

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!