永发信息网

安卓日历整体布局是怎么实现的

答案:1  悬赏:20  手机版
解决时间 2021-11-30 13:02
  • 提问者网友:夢醒日落
  • 2021-11-29 15:11
安卓日历整体布局是怎么实现的
最佳答案
  • 五星知识达人网友:酒醒三更
  • 2021-11-29 16:25
自定义日历控件,支持旧历、节气、日期标注、点击操作 (参考网络上的日历控件改写)
注:将下面的四张资源图片拷贝到所建包的下一个image目录中,如Calendar.java 所在包为
cc.util.android.view,则需要再创建一个包cc.util.android.view.image 然后将图片拷贝进去

package cc.util.android.view;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.text.TextUtils.TruncateAt;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ViewFlipper;
import android.widget.AbsListView.LayoutParams;


public class CalendarView extends LinearLayout implements OnTouchListener,
AnimationListener, OnGestureListener {


public interface OnCalendarViewListener {
void onCalendarItemClick(CalendarView view, Date date);
}


private final static int TOP_HEIGHT = 40;

private final static int DEFAULT_ID = 0xff0000;

// 判断手势用
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;

// 屏幕宽度和高度
private int screenWidth;

// 动画
private Animation slideLeftIn;
private Animation slideLeftOut;
private Animation slideRightIn;
private Animation slideRightOut;
private ViewFlipper viewFlipper;
private GestureDetector mGesture = null;


private GridView gView1;

private GridView gView2;

private GridView gView3;

boolean bIsSelection = false;// 是否是选择事件发生
private Calendar calStartDate = Calendar.getInstance();// 当前显示的日历
private Calendar calSelected = Calendar.getInstance(); // 选择的日历
private CalendarGridViewAdapter gAdapter;
private CalendarGridViewAdapter gAdapter1;
private CalendarGridViewAdapter gAdapter3;

private LinearLayout mMainLayout;
private TextView mTitle; // 显示年月

private int iMonthViewCurrentMonth = 0; // 当前视图月
private int iMonthViewCurrentYear = 0; // 当前视图年

private static final int caltitleLayoutID = 66; // title布局ID
private static final int calLayoutID = 55; // 日历布局ID
private Context mContext;


private final List markDates;

private OnCalendarViewListener mListener;

public CalendarView(Context context) {
this(context, null);
}

public CalendarView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
mContext = context;
markDates = new ArrayList();
init();
}

// 初始化相关工作
protected void init() {
// 得到屏幕的宽度
screenWidth = mContext.getResources().getDisplayMetrics().widthPixels;

// 滑动的动画
slideLeftIn = new TranslateAnimation(screenWidth, 0, 0, 0);
slideLeftIn.setDuration(400);
slideLeftIn.setAnimationListener(this);
slideLeftOut = new TranslateAnimation(0, -screenWidth, 0, 0);
slideLeftOut.setDuration(400);
slideLeftOut.setAnimationListener(this);
slideRightIn = new TranslateAnimation
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯