Android自定义日历滑动控件-创新互联

本文实例为大家分享了Android自定义日历滑动控件的使用方法,供大家参考,具体内容如下

站在用户的角度思考问题,与客户深入沟通,找到苍南网站设计与苍南网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站建设、成都做网站、企业官网、英文网站、手机端网站、网站推广、域名注册、网页空间、企业邮箱。业务覆盖苍南地区。


最近公司项目需要做这个需求,自己才疏学浅,总算能写出个大概来,遂在这里记录下来。

分析

先来分析一下:


首先,我们的需求是可以左右点击查看跳转到下一个月,中间的日历控件可以水平滚动选择日期,所以我们中间的日历控件用一个RecycleView来做,左右两位的为ImageVeiw。
LRCalendarView 总体流程:

  • 编写LRCalendarView的布局R.layout.calendar_view
  • 新建类LRCalendarView继承LinearLayout
  • LRCalendarView添加布局R.layout.calendar_view
  • 数据初始化
  • 构建GalleryAdapter
  • 给RecycleView设置GalleryAdapter并且给左右按钮添加点击事件
  • 处理左右日历翻页逻辑
  • 按需要给RecycleView添加item的点击事件

1. R.layout.calendar_view

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/activity_main"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="#ffffff"
  android:padding="5dp"
  android:orientation="horizontal">

  <ImageView
    android:id="@+id/iv_left"
    android:layout_gravity="center_vertical"
    android:src="@drawable/ic_launcher"
    android:layout_width="31dp"
    android:layout_height="31dp"/>

  <android.support.v7.widget.RecyclerView
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:id="@+id/recyclerView"
    android:layout_width="wrap_content"
    android:layout_weight="1"
    android:layout_height="50dp"
    android:layout_centerVertical="true"
    android:background="#ffffff"
    android:scrollbars="none" />

  <ImageView
    android:id="@+id/iv_right"
    android:layout_gravity="center_vertical"
    android:src="@drawable/ic_launcher"
    android:layout_width="30dp"
    android:layout_height="30dp"/>

</LinearLayout>

新闻名称:Android自定义日历滑动控件-创新互联
文章URL:https://www.cdcxhl.com/article32/dppcsc.html

成都网站建设公司_创新互联,为您提供外贸网站建设外贸建站电子商务定制网站软件开发建站公司

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

绵阳服务器托管