title: How can I create a weekly calendar view for an Android Honeycomb application?
body: <p>I am working on an Android (v3.0) application that has a requirement of mimicking the weekly calendar layout found on Google Calendar:</p>
  
  <p><img src="https://i.stack.imgur.com/WMdSD.jpg" alt="Google Calendar Weekly Layout"></p>
  
  <p>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.</p>
  
  <p>Here's what I have so far:</p>
  
  <p><img src="https://i.stack.imgur.com/SXATR.jpg" alt="My Prototype Calendar View"></p>
  
  <p>The XML appears below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="800dp"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Calendar Title"
          android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
      &lt;RelativeLayout
          android:id="@+id/relativeLayout1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
  
          &lt;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" &gt;
  
              &lt;TextView
                  android:id="@+id/textView2"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_weight="1"
                  android:text="" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView3"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_weight="2"
                  android:gravity="center"
                  android:text="Sunday" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView4"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_weight="2"
                  android:gravity="center"
                  android:text="Monday" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView5"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_weight="2"
                  android:gravity="center"
                  android:text="Tuesday" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView6"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_weight="2"
                  android:gravity="center"
                  android:text="Wednesday" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView7"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_weight="2"
                  android:gravity="center"
                  android:text="Thursday" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView8"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_weight="2"
                  android:gravity="center"
                  android:text="Friday" /&gt;
  
              &lt;TextView
                  android:id="@+id/textView9"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_weight="2"
                  android:gravity="center"
                  android:text="Saturday" /&gt;
          &lt;/LinearLayout&gt;
      &lt;/RelativeLayout&gt;
  
      &lt;ScrollView
          android:id="@+id/scrollView1"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:padding="0dp"
          android:scrollbars="none" &gt;"
  
          &lt;RelativeLayout
              android:id="@+id/relativeLayout242"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:padding="0dp" &gt;
  
  
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="0dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="40dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="80dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="120dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="160dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="200dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="240dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="280dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="320dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="360dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="400dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="440dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="480dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="520dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="560dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="600dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="640dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="680dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="720dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="760dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="800dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="840dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="880dp"/&gt;
              &lt;View android:background="#aaa" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="920dp"/&gt;
  
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="20dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="60dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="100dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="140dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="180dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="220dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="260dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="300dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="340dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="380dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="420dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="460dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="500dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="540dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="580dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="620dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="660dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="700dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="740dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="780dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="820dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="860dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="900dp"/&gt;
              &lt;View android:background="#777" android:layout_width = "fill_parent" android:layout_height="1dp" android:layout_marginTop="940dp"/&gt;
  
              &lt;LinearLayout
                  android:id="@+id/linearLayout2"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:padding="0dp" &gt;
  
                  &lt;RelativeLayout
                      android:id="@+id/relativeLayout2"
                      android:layout_width="0dp"
                      android:layout_height="match_parent"
                      android:layout_weight="1"
                      android:padding="0dp" &gt;
  
                      &lt;View android:background="#aaa" android:layout_width = "1dp" android:layout_height="fill_parent" android:layout_alignParentRight="true"/&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
  
                      &lt;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" /&gt;
                  &lt;/RelativeLayout&gt;
  
                  &lt;RelativeLayout
                      android:id="@+id/relativeLayout3"
                      android:layout_width="0dp"
                      android:layout_height="match_parent"
                      android:layout_weight="14"
                      android:padding="0dp" &gt;
  
                      &lt;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" &gt;
  
                          &lt;RelativeLayout
                              android:id="@+id/relativeLayout4"
                              android:layout_width="0dp"
                              android:layout_height="match_parent"
                              android:layout_weight="1" &gt;
  
                              &lt;View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="180dp" android:layout_marginTop="180dp"/&gt;
  
                              &lt;Button
                                  android:id="@+id/button1"
                                  android:layout_width="fill_parent"
                                  android:layout_height="180dp"
                                  android:layout_marginTop="180dp"
                                  android:text="Some Event" /&gt;
  
                          &lt;/RelativeLayout&gt;
  
                          &lt;RelativeLayout
                              android:id="@+id/relativeLayout5"
                              android:layout_width="0dp"
                              android:layout_height="match_parent"
                              android:layout_weight="1" &gt;
  
                              &lt;View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="180dp" android:layout_marginTop="280dp"/&gt;
  
                              &lt;Button
                                  android:id="@+id/button1"
                                  android:layout_width="fill_parent"
                                  android:layout_height="180dp"
                                  android:layout_marginTop="280dp"
                                  android:text="Some Event" /&gt;
  
                          &lt;/RelativeLayout&gt;
  
                          &lt;RelativeLayout
                              android:id="@+id/relativeLayout6"
                              android:layout_width="0dp"
                              android:layout_height="match_parent"
                              android:layout_weight="1" &gt;
  
                              &lt;View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="60dp" android:layout_marginTop="40dp"/&gt;
  
                              &lt;Button
                                  android:id="@+id/button1"
                                  android:layout_width="fill_parent"
                                  android:layout_height="60dp"
                                  android:layout_marginTop="40dp"
                                  android:text="Some Event" /&gt;
  
                          &lt;/RelativeLayout&gt;
  
                          &lt;RelativeLayout
                              android:id="@+id/relativeLayout7"
                              android:layout_width="0dp"
                              android:layout_height="match_parent"
                              android:layout_weight="1" &gt;
  
                              &lt;View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="90dp" android:layout_marginTop="60dp"/&gt;
  
                              &lt;Button
                                  android:id="@+id/button1"
                                  android:layout_width="fill_parent"
                                  android:layout_height="90dp"
                                  android:layout_marginTop="60dp"
                                  android:text="Some Event" /&gt;
  
                              &lt;View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="120dp" android:layout_marginTop="340dp"/&gt;
  
                              &lt;Button
                                  android:id="@+id/button1"
                                  android:layout_width="fill_parent"
                                  android:layout_height="120dp"
                                  android:layout_marginTop="340dp"
                                  android:text="Some Event" /&gt;
  
                          &lt;/RelativeLayout&gt;
  
                          &lt;RelativeLayout
                              android:id="@+id/relativeLayout8"
                              android:layout_width="0dp"
                              android:layout_height="match_parent"
                              android:layout_weight="1" &gt;
  
                              &lt;View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="180dp" android:layout_marginTop="380dp"/&gt;
  
                              &lt;Button
                                  android:id="@+id/button1"
                                  android:layout_width="fill_parent"
                                  android:layout_height="180dp"
                                  android:layout_marginTop="380dp"
                                  android:text="Some Event" /&gt;
  
                          &lt;/RelativeLayout&gt;
  
                          &lt;RelativeLayout
                              android:id="@+id/relativeLayout9"
                              android:layout_width="0dp"
                              android:layout_height="match_parent"
                              android:layout_weight="1" &gt;
  
                              &lt;View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="180dp" android:layout_marginTop="480dp"/&gt;
  
                              &lt;Button
                                  android:id="@+id/button1"
                                  android:layout_width="fill_parent"
                                  android:layout_height="180dp"
                                  android:layout_marginTop="480dp"
                                  android:text="Some Event" /&gt;
  
                          &lt;/RelativeLayout&gt;
  
                          &lt;RelativeLayout
                              android:id="@+id/relativeLayout10"
                              android:layout_width="0dp"
                              android:layout_height="match_parent"
                              android:layout_weight="1" &gt;
  
                              &lt;View android:background="#00f" android:layout_width = "fill_parent" android:layout_height="180dp" android:layout_marginTop="340dp"/&gt;
  
                              &lt;Button
                                  android:id="@+id/button1"
                                  android:layout_width="fill_parent"
                                  android:layout_height="180dp"
                                  android:layout_marginTop="340dp"
                                  android:text="Some Event" /&gt;
  
                          &lt;/RelativeLayout&gt;           
  
                      &lt;/LinearLayout&gt;
                  &lt;/RelativeLayout&gt;
              &lt;/LinearLayout&gt;
          &lt;/RelativeLayout&gt;
      &lt;/ScrollView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>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).</p>
  
  <p><strong>My questions are:</strong></p>
  
  <ol>
  <li>Is there a better way of doing this?</li>
  <li>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)</li>
  </ol>
  
  <p>Thank you!</p>