日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

android自定义日历代码,Android自定义日历Calender代码实现

發布時間:2024/8/1 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android自定义日历代码,Android自定义日历Calender代码实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

產品要做簽到功能,簽到功能要基于一個日歷來進行,所以就根據 要求自定義了一個日歷

自定義控件相信做android都知道:

(1)首先創建一個類,繼承一個容器類或者是一個控件

(2)然后就是你需要設置的屬性等的,在attrs文件夾中

(3)然后就是在類里邊進行屬性的設置以及布局等等功能的添加

其實自定義一個日歷問題都不多,很多人都會想到通過一個gridView然后填充就可以,確實是這樣,主要是在顯示每個月的第一天的位置以及每個月顯示多少天有點繞。

思路:通過判斷當前星期幾然后進行日歷的填充,但是填充的大小不能大于當月天數,通過當月第一天是星期幾來判斷從哪個位置填充。

代碼:

package com.example.calenderdemo;

import android.content.Context;

import android.graphics.Color;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.BaseAdapter;

import android.widget.TextView;

public class CalendarViewAdapter extends BaseAdapter {

private Context mContext;

private int mCountDay = 49;

private int mCurrent_mouth_Countday;

private int mCurrent_Week;

private int id[] = { R.string.week7, R.string.week1, R.string.week2,

R.string.week3, R.string.week4, R.string.week5, R.string.week6 };

public CalendarViewAdapter(Context context, int countday) {

this.mContext = context;

this.mCurrent_Week = Utils.getCurrentMonthStart();

this.mCurrent_mouth_Countday = countday;

}

@Override

public int getCount() {

return mCountDay;

}

@Override

public Object getItem(int position) {

return null;

}

@Override

public long getItemId(int position) {

return position;

}

@Override

public View getView(int position, View convertView, ViewGroup parent) {

ViewHolder holder = null;

if (convertView == null) {

holder = new ViewHolder();

convertView = LayoutInflater.from(mContext).inflate(

R.layout.item_calendar, null);

holder.mTv_calendar_day = (TextView) convertView

.findViewById(R.id.tv_calendar_day);

convertView.setTag(holder);

} else

holder = (ViewHolder) convertView.getTag();

if (position <= 6) {

holder.mTv_calendar_day.setTextColor(Color.BLACK);

holder.mTv_calendar_day.setTextSize(mContext.getResources()

.getDimension(R.dimen.text_size_7));

holder.mTv_calendar_day.setText(mContext.getResources().getString(

id[position]));

} else {

if (mCurrent_Week == 7 && (position -6) <= mCurrent_mouth_Countday) {

holder.mTv_calendar_day.setText(position-6 + "");

} else if (position -7>= mCurrent_Week

&& position - mCurrent_Week -6 <= mCurrent_mouth_Countday) {

holder.mTv_calendar_day.setText(position - mCurrent_Week -6

+ "");

}

}

if (position % 7 == 6) {

holder.mTv_calendar_day.setBackgroundResource(R.drawable.line_right);

}else if (position % 7 == 0) {

holder.mTv_calendar_day.setBackgroundResource(R.drawable.line_left);

}

return convertView;

}

class ViewHolder {

TextView mTv_calendar_day;

}

}

把gridView填充了以后一個簡單的日歷控件就ok了。

自定義了一個日歷以后就要做簽到了,簽到只要在自定義的Calendar中稍稍修改下就好了,看下效果圖:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

總結

以上是生活随笔為你收集整理的android自定义日历代码,Android自定义日历Calender代码实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。