本文实例为大家分享了Android自定义日历滑动控件的使用方法,供大家参考,具体内容如下
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; LinearLayout & lt; 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:背景=" # ffffff " android:填充=" 5 dp " 面向android:="水平"比; & lt; ImageView android: id=癅 + id/iv_left” android: layout_gravity=" center_vertical " android: src=" https://www.yisu.com/zixun/@drawable ic_launcher " android: layout_width=" 31 dp " android: layout_height=?1 dp/比; & lt; android.support.v7.widget.RecyclerView android: layout_marginLeft=" 5 dp " android: layout_marginRight=" 5 dp " android: id=癅 + id/recyclerView” android: layout_width=" wrap_content " android: layout_weight=" 1 " android: layout_height=" 50 dp” android: layout_centerVertical=" true " android:背景=" # ffffff " android:滚动条="没有"/比; & lt; ImageView android: id=癅 + id/iv_right” android: layout_gravity=" center_vertical " android: src=" https://www.yisu.com/zixun/@drawable ic_launcher " android: layout_width=" 30 dp " android: layout_height=" 30 dp/比; & lt;/LinearLayout>
2。新建类LRCalendarView继承LinearLayout并添加布局
公开课LRCalendarView LinearLayout{延伸 私人上下文语境; 私人ImageView ivLeft ivRight; 私人RecyclerView mRecyclerView; 私人GalleryAdapter mAdapter; 私人Listdata=https://www.yisu.com/zixun/new ArrayList <> (); 私人int mCurrYear mCurrMonth mCurrDay; 私人int mSelYear mSelMonth mSelDay;//今天的日期的位置 私人int todayPos; 公共LRCalendarView(上下文语境、AttributeSet attrs int defStyleAttr) { 超级(上下文、attrs defStyleAttr); 这一点。上下文=上下文; setupView(上下文); } 公共LRCalendarView(上下文语境,AttributeSet attrs) { 这(上下文、attrs 0); } 公共LRCalendarView(上下文语境){ 这(上下文,null); }/* * *初始化控件 */私人空间setupView(最终上下文语境){ 视图视图=LayoutInflater.from(上下文).inflate (R.layout.calendar_view, null); this.addView(查看); data=init (); mRecyclerView=(RecyclerView) findViewById (R.id.recyclerView); ivLeft=(ImageView) findViewById (R.id.iv_left); ivRight=(ImageView) findViewById (R.id.iv_right);//设置马槽 LinearLayoutManager LinearLayoutManager=new LinearLayoutManager(上下文); linearLayoutManager.setOrientation (LinearLayoutManager.HORIZONTAL); mRecyclerView.setLayoutManager (linearLayoutManager);//设置适配器 mAdapter=new GalleryAdapter(上下文,init ()); mRecyclerView.setAdapter (mAdapter); } } |
公共类细胞{ 私人的字符串; 私人弦月; 私人int mCurrDay; 私人布尔isSelect; 公共int getmCurrDay () { 返回mCurrDay; } 公共空间setmCurrDay (int mCurrDay) { 这一点。mCurrDay=mCurrDay; } 公共字符串getDay () { 返回一天; } 公共空间setDay (String) { 这一点。一天=一天; } 公共字符串getMonth () { 返回月; } 公共空间setMonth (String) { 这一点。月=月; } 公共布尔isSelect () { 返回isSelect; } 公共空间setSelect(布尔选择){ isSelect=选择; } }Android自定义日历滑动控件