仿小米日历功能,Android week view

论坛 期权论坛     
选择匿名的用户   2021-6-2 16:29   155   0
<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:&#39;Microsoft YaHei&#39;;"> 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">&lt;</span><span class="tag-name">RelativeLayout</span> <span class="attribute">xmlns:android</span>&#61;<span class="attribute-value">&#34;http://schemas.android.com/apk/res/android&#34;</span>  </li><li>    <span class="attribute">xmlns:app</span>&#61;<span class="attribute-value">&#34;http://schemas.android.com/apk/res-auto&#34;</span>  </li><li class="alt">    <span class="attribute">xmlns:tools</span>&#61;<span class="attribute-value">&#34;http://schemas.android.com/tools&#34;</span>  </li><li>    <span class="attribute">android:layout_width</span>&#61;<span class="attribute-value">&#34;match_parent&#34;</span>  </li><li class="alt">    <span class="attribute">android:layout_height</span>&#61;<span class="attribute-value">&#34;match_parent&#34;</span>  </li><li>    <span class="attribute">tools:context</span>&#61;<span class="attribute-value">&#34;.MainActivity&#34;</span><span class="tag">&gt;</span>  </li><li class="alt">  </li><li>    <span class="tag">&lt;</span><span class="tag-name">TextView</span>  </li><li class="alt">        <span class="attribute">android:id</span>&#61;<span class="attribute-value">&#34;&#64;&#43;id/tv_date&#34;</span>  </li><li>        <span class="attribute">android:layout_width</span>&#61;<span class="attribute-value">&#34;match_parent&#34;</span>  </li><li class="alt">        <span class="attribute">android:layout_height</span>&#61;<span class="attribute-value">&#34;30dp&#34;</span>  </li><li>        <span class="attribute">android:background</span>&#61;<span class="attribute-value">&#34;#455964&#34;</span>  </li><li class="alt">        <span class="attribute">android:gravity</span>&#61;<span class="attribute-value">&#34;center&#34;</span>  </li><li>        <span class="attribute">android:text</span>&#61;<span class="attribute-value">&#34;2015年1月&#34;</span>  </li><li class="alt">        <span class="attribute">android:textColor</span>&#61;<span class="attribute-value">&#34;#ffffff&#34;</span>  </li><li>        <span class="attribute">android:textSize</span>&#61;<span class="attribute-value">&#34;16sp&#34;</span><span class="tag">/&gt;</span>  </li><li class="alt">  </li><li>    <span class="tag">&lt;</span><span class="tag-name">com.guojunustb.library.WeekHeaderView</span>  </li><li class="alt">        <span class="attribute">android:id</span>&#61;<span class="attribute-value">&#34;&#64;&#43;id/weekheaderview&#34;</span>  </li><li>        <span class="attribute">android:layout_width</span>&#61;<span class="attribute-value">&#34;match_parent&#34;</span>  </li><li class="alt">        <span class="attribute">android:layout_height</span>&#61;<span class="attribute-value">&#34;wrap_content&#34;</span>  </li><li>        <span class="attribute">android:layout_below</span>&#61;<span class="attribute-value">&#34;&#64;&#43;id/tv_date&#34;</span>  </li><li class="alt">        <span class="attribute">app:firstDayOfWeek2</span>&#61;<span class="attribute-value">&#34;sunday&#34;</span>  </li><li>        <span class="attribute">app:headerBackgroundColor</span>&#61;<span class="attribute-value">&#34;#455964&#34;</span>  </li><li class="
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP