如何创建一个Android蜂窝应用程序每周日历视图? [英] How can I create a weekly calendar view for an Android Honeycomb application?
问题描述
我的工作在Android(3.0)应用程序,有模仿的谷歌日历中的周历布局的要求:
该事件将基础上,通过谷歌日历API外部请求(我已经有这部分工作)。使用该API,我可以得到为一周的事件列表,与具有每个事件的开始和结束以及日期时间。我想用这个数据来显示预定的事件给应用程序的用户以类似于以上所述一个的图。
这是我到目前为止有:
下面的XML显示:
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =800DP
机器人:layout_height =match_parent
机器人:方向=垂直>
<的TextView
机器人:ID =@ + ID / textView1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=日历标题
机器人:textAppearance =:/>中的Android ATTR / textAppearanceLarge?
< RelativeLayout的
机器人:ID =@ + ID / relativeLayout1
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT>
<的LinearLayout
机器人:ID =@ + ID / linearLayout1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真
机器人:layout_alignParentRight =真
机器人:layout_alignParentTop =真正的>
<的TextView
机器人:ID =@ + ID / textView2
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1
机器人:文本=/>
<的TextView
机器人:ID =@ + ID / textView3
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =2
机器人:重力=中心
机器人:文本=星期天/>
<的TextView
机器人:ID =@ + ID / textView4
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =2
机器人:重力=中心
机器人:文本=星期一/>
<的TextView
机器人:ID =@ + ID / textView5
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =2
机器人:重力=中心
机器人:文本=星期二/>
<的TextView
机器人:ID =@ + ID / textView6
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =2
机器人:重力=中心
机器人:文本=星期三/>
<的TextView
机器人:ID =@ + ID / textView7
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =2
机器人:重力=中心
机器人:文本=星期四/>
<的TextView
机器人:ID =@ + ID / textView8
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =2
机器人:重力=中心
机器人:文本=星期五/>
<的TextView
机器人:ID =@ + ID / textView9
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =2
机器人:重力=中心
机器人:文本=星期六/>
< / LinearLayout中>
< / RelativeLayout的>
<滚动型
机器人:ID =@ + ID / scrollView1
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:填充=0dp
机器人:滚动条=无>中
< RelativeLayout的
机器人:ID =@ + ID / relativeLayout242
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:填充=0dp>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =0dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =40dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =80dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =120dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =160dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =200dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =240dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =280dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =320dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =360dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =400dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =440dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =480dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =520dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =560dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =600dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =640dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =680dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =720dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =760dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =800DP/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =840dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =880dp/>
<查看机器人:后台=#AAA机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =920dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =20dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =60dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =100dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =140dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =180dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =220DP/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =260dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =300dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =340dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =380dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =420dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =460dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =500dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =540dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =580dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =620dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =660dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =700dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =740dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =780dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =820DP/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =860dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =900dp/>
<查看机器人:后台=#777机器人:layout_width =FILL_PARENT机器人:layout_height =1DP机器人:layout_marginTop =940dp/>
<的LinearLayout
机器人:ID =@ + ID / linearLayout2
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:填充=0dp>
< RelativeLayout的
机器人:ID =@ + ID / relativeLayout2
机器人:layout_width =0dp
机器人:layout_height =match_parent
机器人:layout_weight =1
机器人:填充=0dp>
<查看机器人:后台=#AAA机器人:layout_width =1DP机器人:layout_height =FILL_PARENT机器人:layout_alignParentRight =真/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =0dp
机器人:重力=中心
机器人:文本=上午12点/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =40dp
机器人:重力=中心
机器人:文本=凌晨一点/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =80dp
机器人:重力=中心
机器人:文本=上午02/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =120dp
机器人:重力=中心
机器人:文本=凌晨3点/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =160dp
机器人:重力=中心
机器人:文本=凌晨4点/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =200dp
机器人:重力=中心
机器人:文本=上午05点/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =240dp
机器人:重力=中心
机器人:文本=早上6点/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =280dp
机器人:重力=中心
机器人:文本=早上7点/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =320dp
机器人:重力=中心
机器人:文本=上午8/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =360dp
机器人:重力=中心
机器人:文本=上午9时/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =400dp
机器人:重力=中心
机器人:文本=上午10点/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =440dp
机器人:重力=中心
机器人:文本=11点/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =480dp
机器人:重力=中心
机器人:文本=12点/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =520dp
机器人:重力=中心
机器人:文本=下午1时/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =560dp
机器人:重力=中心
机器人:文本=14:00/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =600dp
机器人:重力=中心
机器人:文本=15:00/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =640dp
机器人:重力=中心
机器人:文本=4点/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =680dp
机器人:重力=中心
机器人:文本=17:00/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =720dp
机器人:重力=中心
机器人:文本=下午6点/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =760dp
机器人:重力=中心
机器人:文本=晚上7点/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =800DP
机器人:重力=中心
机器人:文本=晚上8点/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =840dp
机器人:重力=中心
机器人:文本=晚上9点/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =880dp
机器人:重力=中心
机器人:文本=10点/>
<的TextView
机器人:ID =@ + ID / textView10
机器人:layout_width =match_parent
机器人:layout_height =40dp
机器人:layout_marginTop =920dp
机器人:重力=中心|顶
机器人:文本=11点/>
< / RelativeLayout的>
< RelativeLayout的
机器人:ID =@ + ID / relativeLayout3
机器人:layout_width =0dp
机器人:layout_height =match_parent
机器人:layout_weight =14
机器人:填充=0dp>
<的LinearLayout
机器人:ID =@ + ID / linearLayout3
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真
机器人:layout_alignParentRight =真
机器人:layout_alignParentTop =真
机器人:填充=0dp>
< RelativeLayout的
机器人:ID =@ + ID / relativeLayout4
机器人:layout_width =0dp
机器人:layout_height =match_parent
机器人:layout_weight =1>
<查看机器人:后台=#00F机器人:layout_width =FILL_PARENT机器人:layout_height =180dp机器人:layout_marginTop =180dp/>
<按钮
机器人:ID =@ + ID /按钮1
机器人:layout_width =FILL_PARENT
机器人:layout_height =180dp
机器人:layout_marginTop =180dp
机器人:文本=一些事件/>
< / RelativeLayout的>
< RelativeLayout的
机器人:ID =@ + ID / relativeLayout5
机器人:layout_width =0dp
机器人:layout_height =match_parent
机器人:layout_weight =1>
<查看机器人:后台=#00F机器人:layout_width =FILL_PARENT机器人:layout_height =180dp机器人:layout_marginTop =280dp/>
<按钮
机器人:ID =@ + ID /按钮1
机器人:layout_width =FILL_PARENT
机器人:layout_height =180dp
机器人:layout_marginTop =280dp
机器人:文本=一些事件/>
< / RelativeLayout的>
< RelativeLayout的
机器人:ID =@ + ID / relativeLayout6
机器人:layout_width =0dp
机器人:layout_height =match_parent
机器人:layout_weight =1>
<查看机器人:后台=#00F机器人:layout_width =FILL_PARENT机器人:layout_height =60dp机器人:layout_marginTop =40dp/>
<按钮
机器人:ID =@ + ID /按钮1
机器人:layout_width =FILL_PARENT
机器人:layout_height =60dp
机器人:layout_marginTop =40dp
机器人:文本=一些事件/>
< / RelativeLayout的>
< RelativeLayout的
机器人:ID =@ + ID / relativeLayout7
机器人:layout_width =0dp
机器人:layout_height =match_parent
机器人:layout_weight =1>
<查看机器人:后台=#00F机器人:layout_width =FILL_PARENT机器人:layout_height =90dp机器人:layout_marginTop =60dp/>
<按钮
机器人:ID =@ + ID /按钮1
机器人:layout_width =FILL_PARENT
机器人:layout_height =90dp
机器人:layout_marginTop =60dp
机器人:文本=一些事件/>
<查看机器人:后台=#00F机器人:layout_width =FILL_PARENT机器人:layout_height =120dp机器人:layout_marginTop =340dp/>
<按钮
机器人:ID =@ + ID /按钮1
机器人:layout_width =FILL_PARENT
机器人:layout_height =120dp
机器人:layout_marginTop =340dp
机器人:文本=一些事件/>
< / RelativeLayout的>
< RelativeLayout的
机器人:ID =@ + ID / relativeLayout8
机器人:layout_width =0dp
机器人:layout_height =match_parent
机器人:layout_weight =1>
<查看机器人:后台=#00F机器人:layout_width =FILL_PARENT机器人:layout_height =180dp机器人:layout_marginTop =380dp/>
<按钮
机器人:ID =@ + ID /按钮1
机器人:layout_width =FILL_PARENT
机器人:layout_height =180dp
机器人:layout_marginTop =380dp
机器人:文本=一些事件/>
< / RelativeLayout的>
< RelativeLayout的
机器人:ID =@ + ID / relativeLayout9
机器人:layout_width =0dp
机器人:layout_height =match_parent
机器人:layout_weight =1>
<查看机器人:后台=#00F机器人:layout_width =FILL_PARENT机器人:layout_height =180dp机器人:layout_marginTop =480dp/>
<按钮
机器人:ID =@ + ID /按钮1
机器人:layout_width =FILL_PARENT
机器人:layout_height =180dp
机器人:layout_marginTop =480dp
机器人:文本=一些事件/>
< / RelativeLayout的>
< RelativeLayout的
机器人:ID =@ + ID / relativeLayout10
机器人:layout_width =0dp
机器人:layout_height =match_parent
机器人:layout_weight =1>
<查看机器人:后台=#00F机器人:layout_width =FILL_PARENT机器人:layout_height =180dp机器人:layout_marginTop =340dp/>
<按钮
机器人:ID =@ + ID /按钮1
机器人:layout_width =FILL_PARENT
机器人:layout_height =180dp
机器人:layout_marginTop =340dp
机器人:文本=一些事件/>
< / RelativeLayout的>
< / LinearLayout中>
< / RelativeLayout的>
< / LinearLayout中>
< / RelativeLayout的>
< /滚动型>
< / LinearLayout中>
我的做法是使40dp等于1小时的时间。因此,每当我想补充的是具有1.5小时的时间的情况下,我会作出60dp按钮,我将会把在准确位置的时间开始(上午12点= 0dp从顶部,下午1点= 40dp从顶部,下午2点= 80d的从顶部,等等)。
我的问题是:
- 是否有这样做? 更好的办法
- 如何将我的XML是可以添加到任何Android项目的独立看法? (我计划可能使得对最终产品的博客文章)
感谢您!
解决方案我最终下了类似的做法,以我原来的职位
下面就是它结束了看起来像一个preVIEW:
这里的XML布局: http://pastebin.com/jT4wQxeb
在code是太长,以适合的答案。
注: calendar_zebra
简直就是一个60 * 24 = 1440dp高,1 DP高水平查看
s的布局坚实的灰色背景放在每个60dp。每次重新presents一个标志为一个小时的时间。
I am working on an Android (v3.0) application that has a requirement of mimicking the weekly calendar layout found on Google Calendar:
The events will be based on external requests through the Google Calendar API (I already have this part working). Using the API, I can obtain a list of events for the week, with each event having a starting and and ending datetime. I would like to use this data to show the scheduled events to the application's users in a view similar to the one above.
Here's what I have so far:
The XML appears below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="800dp"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calendar Title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="Sunday" />
<TextView
android:id="@+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="Monday" />
<TextView
android:id="@+id/textView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="Tuesday" />
<TextView
android:id="@+id/textView6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="Wednesday" />
<TextView
android:id="@+id/textView7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="Thursday" />
<TextView
android:id="@+id/textView8"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="Friday" />
<TextView
android:id="@+id/textView9"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="Saturday" />
</LinearLayout>
</RelativeLayout>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
android:scrollbars="none" >"
<RelativeLayout
android:id="@+id/relativeLayout242"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dp" >
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="0dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="40dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="80dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="120dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="160dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="200dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="240dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="280dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="320dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="360dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="400dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="440dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="480dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="520dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="560dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="600dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="640dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="680dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="720dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="760dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="800dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="840dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="880dp"/>
<View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="920dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="20dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="60dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="100dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="140dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="180dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="220dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="260dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="300dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="340dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="380dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="420dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="460dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="500dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="540dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="580dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="620dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="660dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="700dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="740dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="780dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="820dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="860dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="900dp"/>
<View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="940dp"/>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dp" >
<RelativeLayout
android:id="@+id/relativeLayout2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="0dp" >
<View android:background="#aaa" android:layout_width = "1dp" android:layout_height="fill_parent" android:layout_alignParentRight="true"/>
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:gravity="center"
android:text="12am" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:gravity="center"
android:text="1am" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:gravity="center"
android:text="2am" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"
android:gravity="center"
android:text="3am" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="160dp"
android:gravity="center"
android:text="4am" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:gravity="center"
android:text="5am" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="240dp"
android:gravity="center"
android:text="6am" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="280dp"
android:gravity="center"
android:text="7am" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="320dp"
android:gravity="center"
android:text="8am" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="360dp"
android:gravity="center"
android:text="9am" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="400dp"
android:gravity="center"
android:text="10am" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="440dp"
android:gravity="center"
android:text="11am" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="480dp"
android:gravity="center"
android:text="12pm" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="520dp"
android:gravity="center"
android:text="1pm" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="560dp"
android:gravity="center"
android:text="2pm" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="600dp"
android:gravity="center"
android:text="3pm" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="640dp"
android:gravity="center"
android:text="4pm" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="680dp"
android:gravity="center"
android:text="5pm" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="720dp"
android:gravity="center"
android:text="6pm" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="760dp"
android:gravity="center"
android:text="7pm" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="800dp"
android:gravity="center"
android:text="8pm" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="840dp"
android:gravity="center"
android:text="9pm" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="880dp"
android:gravity="center"
android:text="10pm" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="920dp"
android:gravity="center|top"
android:text="11pm" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="14"
android:padding="0dp" >
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:padding="0dp" >
<RelativeLayout
android:id="@+id/relativeLayout4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="180dp" android:layout_marginTop="180dp"/>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="180dp"
android:layout_marginTop="180dp"
android:text="Some Event" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout5"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="180dp" android:layout_marginTop="280dp"/>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="180dp"
android:layout_marginTop="280dp"
android:text="Some Event" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout6"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="60dp" android:layout_marginTop="40dp"/>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_marginTop="40dp"
android:text="Some Event" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout7"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="90dp" android:layout_marginTop="60dp"/>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_marginTop="60dp"
android:text="Some Event" />
<View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="120dp" android:layout_marginTop="340dp"/>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="120dp"
android:layout_marginTop="340dp"
android:text="Some Event" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout8"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="180dp" android:layout_marginTop="380dp"/>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="180dp"
android:layout_marginTop="380dp"
android:text="Some Event" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout9"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="180dp" android:layout_marginTop="480dp"/>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="180dp"
android:layout_marginTop="480dp"
android:text="Some Event" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout10"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="180dp" android:layout_marginTop="340dp"/>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="180dp"
android:layout_marginTop="340dp"
android:text="Some Event" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
My approach was to make 40dp equal to 1 hr of time. Thus, whenever I would like to add an event that has a duration of 1.5 hours, I will make an 60dp button that I will place at the exact location that the time begins (12am = 0dp from the top, 1pm = 40dp from the top, 2pm = 80d from the top, etc).
My questions are:
- Is there a better way of doing this?
- How can I convert my XML to be stand-alone view that could be added to any Android project? (I plan on perhaps making a blog post about the end product)
Thank you!
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 View
s with a solid gray background placed every 60dp. Each represents a marker for an hour of time.
这篇关于如何创建一个Android蜂窝应用程序每周日历视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!