<p><strong><span style="font-size:24px;">前言</span></strong></p>
<p><span style="font-size:24px;">最近由于项目需求,要做一个仿小米日历的功能,下面显示一天的日程,header以周为单位进行滑动,github上找了很久也没有找到合适的,但找到一相近的开源项目<a href="https://github.com/alamkanak/Android-Week-View">Android-week-view</a>,它不是我们项目所需要的效果,但是它帮我们实现的Event的添加和事件的处理,这让我们省了不少工作,Android-week-view效果如下图</span></p>
<p><br></p>
<p><img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-5f41abb0134cd179fbc7bcd5ec38f4ed"></p>
<p> 废话不多说,先看看我项目中的效果</p>
<p><img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-00191d6e9fea3f90c94d1c543909d06d"><br></p>
<p><img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-528a619d04dbeab078db0afe6776cf01"><br></p>
<h5> <strong><span style="font-size:18px;">主要包括两个核心的类,两个定义控件,上面的WeekHeaderView和下面的WeekDayView,都是继承的view,然后计算位置,将上面的week label 和下面的Day text 画上去,通过Scroller和<a href="http://blog.csdn.net/aben_2005/article/details/6417423" style="color:rgb(0,0,0);text-decoration:none;font-family:'Microsoft YaHei';"> GestureDetector</a>控制滑动和处理各种事件。废话不多说,直接教大家怎么用。</span></strong></h5>
<div>
<strong><span style="font-size:18px;"> 首先是布局文件,大家可以通过属性去控件文字的大小,背影颜色、焦点颜色等等。</span></strong>
<div class="dp-highlighter bg_html">
<div class="bar">
<div class="tools">
<strong>[html]</strong>
<a class="ViewSource" href="http://blog.csdn.net/guojunustb/article/details/49339065#" title="view plain">view plain</a>
<span class="tracking-ad"> <a class="CopyToClipboard" href="http://blog.csdn.net/guojunustb/article/details/49339065#" title="copy">copy</a></span>
<span class="tracking-ad"> </span>
</div>
</div>
<ol class="dp-xml" start="1"><li class="alt"><span class="tag"><</span><span class="tag-name">RelativeLayout</span> <span class="attribute">xmlns:android</span>=<span class="attribute-value">"http://schemas.android.com/apk/res/android"</span> </li><li> <span class="attribute">xmlns:app</span>=<span class="attribute-value">"http://schemas.android.com/apk/res-auto"</span> </li><li class="alt"> <span class="attribute">xmlns:tools</span>=<span class="attribute-value">"http://schemas.android.com/tools"</span> </li><li> <span class="attribute">android:layout_width</span>=<span class="attribute-value">"match_parent"</span> </li><li class="alt"> <span class="attribute">android:layout_height</span>=<span class="attribute-value">"match_parent"</span> </li><li> <span class="attribute">tools:context</span>=<span class="attribute-value">".MainActivity"</span><span class="tag">></span> </li><li class="alt"> </li><li> <span class="tag"><</span><span class="tag-name">TextView</span> </li><li class="alt"> <span class="attribute">android:id</span>=<span class="attribute-value">"@+id/tv_date"</span> </li><li> <span class="attribute">android:layout_width</span>=<span class="attribute-value">"match_parent"</span> </li><li class="alt"> <span class="attribute">android:layout_height</span>=<span class="attribute-value">"30dp"</span> </li><li> <span class="attribute">android:background</span>=<span class="attribute-value">"#455964"</span> </li><li class="alt"> <span class="attribute">android:gravity</span>=<span class="attribute-value">"center"</span> </li><li> <span class="attribute">android:text</span>=<span class="attribute-value">"2015年1月"</span> </li><li class="alt"> <span class="attribute">android:textColor</span>=<span class="attribute-value">"#ffffff"</span> </li><li> <span class="attribute">android:textSize</span>=<span class="attribute-value">"16sp"</span><span class="tag">/></span> </li><li class="alt"> </li><li> <span class="tag"><</span><span class="tag-name">com.guojunustb.library.WeekHeaderView</span> </li><li class="alt"> <span class="attribute">android:id</span>=<span class="attribute-value">"@+id/weekheaderview"</span> </li><li> <span class="attribute">android:layout_width</span>=<span class="attribute-value">"match_parent"</span> </li><li class="alt"> <span class="attribute">android:layout_height</span>=<span class="attribute-value">"wrap_content"</span> </li><li> <span class="attribute">android:layout_below</span>=<span class="attribute-value">"@+id/tv_date"</span> </li><li class="alt"> <span class="attribute">app:firstDayOfWeek2</span>=<span class="attribute-value">"sunday"</span> </li><li> <span class="attribute">app:headerBackgroundColor</span>=<span class="attribute-value">"#455964"</span> </li><li class=" |
|