//图片下方的码段主要实现了课程表所要显示的基本布局,采用ondraw的方法。

//别的内容可以根据自己兴趣添加,下面是本人做的,仅供参考。
                   

             

package com.example.android_draw;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class Mydraw extends View {
private Paint paintlinev=new Paint();
private Paint paintlineh=new Paint();
private Paint paintjia=new Paint();
private Paint paintnumber=new Paint();
private Paint painttext=new Paint();
private Paint paintselect=new Paint();
private float mousex,mousey;
private static boolean initflag=false;
private static boolean onTouchEventflag=false;
private static int spacew=0; 
private static int spaceh=0; 
private static int[] result=new int[2];
private Bitmap tianjia;
private String 
public Mydraw(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public Mydraw(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}

public Mydraw(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
if(!initflag){
init();
}
drawbackground(canvas);
if(onTouchEventflag){
drawrectangle1(canvas);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
mousex=event.getX();
mousey=event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if(mousex>spacew){
result[0]=(int)((mousex-spacew)/(2*spacew));
onTouchEventflag=true;
}
result[1]=(int)(mousey/(spaceh));

break;
}
Mydraw.this.postInvalidate();
return true;
}

public void drawbackground(Canvas canvas){
canvas.drawLine(spacew, 0, spacew, 12*spaceh, paintlinev);
for(int i=1;i<13;i++){
canvas.drawText(i, spacew/2, spaceh*i*3/4, paintnumber);
}
for(int i=1;i<=12;i+=1){
canvas.drawLine(0, i*spaceh, spacew, i*spaceh, paintlineh);
}
for(int i=1;i<=12;i+=1){
for(int j=3;j<15;j+=2){
canvas.drawLine(j*spacew-2, i*spaceh, j*spacew+3, i*spaceh, paintlineh);

}
}
for(int i=1;i<=12;i+=1){
for(int j=3;j<15;j+=2){
canvas.drawLine(j*spacew, i*spaceh-2, j*spacew, i*spaceh+3, paintlinev);
}
}
}

private void drawrectangle1(Canvas canvas){
// Matrix matrix = new Matrix();
// matrix.preScale(space/tianjia.getWidth(), space/tianjia.getHeight(), result[0]*space, result[1]*space);
// canvas.drawBitmap(tianjia, matrix, paintjia);
canvas.drawBitmap(tianjia, result[0]*2*spacew+spacew, result[1]*spaceh,paintjia);
}
public void init(){
paintlineh.setColor(Color.BLACK);
paintlineh.setStrokeWidth(1);
paintlinev.setColor(Color.BLACK);
paintlinev.setStrokeWidth(1);
paintnumber.setColor(Color.BLACK);
paintnumber.setStrokeWidth(1);

tianjia=BitmapFactory.decodeResource(getResources(), R.drawable.tianjia);
int width=getWidth();
int height=getHeight();

spacew=width/15;

spaceh=height/12;

paintnumber.setTextSize((float) (0.75*height));
paintnumber.setTextAlign(Paint.Align.CENTER);
tianjia=BitmapFactory.decodeResource(getResources(), R.drawable.tianjia);
tianjia=Bitmap.createScaledBitmap(tianjia, 2*spacew, spaceh, false);
initflag=true;
}

}

android课程表的实现的更多相关文章

  1. android课程表控件、悬浮窗、Todo应用、MVP框架、Kotlin完整项目源码

    Android精选源码 Android游戏2048 MVP Kotlin项目(RxJava+Rerotfit+OkHttp+Glide) Android基于自定义Span的富文本编辑器 android ...

  2. android选择器汇总、仿最美应用、通用课程表、卡片动画、智能厨房、阅读客户端等源码

    Android精选源码 android各种 选择器 汇总源码 高仿最美应用项目源码 android通用型课程表效果源码 android实现关键字变色 Android ViewPager卡片视差.拖拽及 ...

  3. android五子棋游戏、资讯阅读、大学课程表、地图拖拽检测、小说搜索阅读app等源码

    Android精选源码 Android 自动生成添加控件 android旋转动画.圆形进度条组合效果源码 一款很强的手机五子棋app源码 android地图拖拽区域检测效果源码 实现Android大学 ...

  4. 发布了Android的App,我要开源几个组件!

    做了一款App,本来是毕业设计但是毕业的时候还没有做完,因为大部分时间都改论文去了,你们都懂的.现在毕业了在工作之余把App基本上做完了.为什么说基本上呢,因为我觉得还有很多功能还没实现,还要很多bu ...

  5. Android 实例子源代码文件下载地址380个合集

      android 城市列表特效 - 触摸查找源码 .rar: http://www.t00y.com/file/64337887 android 日记系统源码(数据库的基本操作) .rar: htt ...

  6. GitHub 优秀的 Android 开源项目(转)

    今天查找资源时看到的一篇文章,总结了很多实用资源,十分感谢原作者分享. 转自:http://blog.csdn.net/shulianghan/article/details/18046021 主要介 ...

  7. Android 学习笔记之AndBase框架学习(五) 数据库ORM..注解,数据库对象映射...

    PS:好久没写博客了... 学习内容: 1.DAO介绍,通用DAO的简单调度过程.. 2.数据库映射关系... 3.使用泛型+反射+注解封装通用DAO.. 4.使用AndBase框架实现对DAO的调用 ...

  8. Android Sqlite 实例入门

    通过一个简单的例子来学习Sqlite,学生选课系统,一开始的需求是学生可以选课,选课完成后可以查询到已经选择的课. 首先设计三个表,学生,课程,选课.学生表存储学生的信息,课程表存储课程的信息,选课表 ...

  9. GitHub 优秀的 Android 开源项目

    转自:http://blog.csdn.net/shulianghan/article/details/18046021 主要介绍那些不错个性化的View,包括ListView.ActionBar.M ...

随机推荐

  1. 图解Activity与Fragment

    文字待补充.. 注:由于图片太大,显示不清晰请谅解.大家可以右键图片-->在新窗口打开,或者保存到本地查看.

  2. 使用C++还是QML

    本质上,Qt 是一个C++类库.在引入 QML 以前,所有的开发都是基于 C++ 的,但到了 Qt 5,QML 和 Qt Quick 成为了 Qt 的核心之一,导致很多初学者在犹豫是否还需要学习 C+ ...

  3. php---分组函数group_concat()

    group_concat()函数总结 group_concat(),手册上说明:该函数返回带有来自一个组的连接的非NULL值的字符串结果.比较抽象,难以理解. 通俗点理解,其实是这样的:group_c ...

  4. 20145211 《Java程序设计》实验报告二:Java面向对象程序设计

    实验要求 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验内容 单元测试 面向对象三要素 设计模式初步 练习 实 ...

  5. Asp.net MVC中Route的理解

    在Asp.net MVC中,对于一个请求,是通过路由找到对应的Controller类中的对应Action,并与model进行交互,最后返回到view. 就是说Asp.net MVC是用Route来定义 ...

  6. 使用sql语句查询日期在一定时间内的数据

    使用sql语句查询日期在一周内的数据 select * from ShopOrder where datediff(week,ordTime,getdate()-1)=0   //查询当天日期在一周年 ...

  7. imx6 生成 spi设备节点

    开发板需要使用spi接口,但是spi接口被touch占用,使用event进行操作.所以需要更改配置,生成spi设备节点. 参考链接 https://community.nxp.com/thread/3 ...

  8. angularJs:动态效果之:显示与隐藏(该例对比了普通赋值,层次赋值,事件的写法对比)

    testShowAndHiddern.html <!DOCTYPE html> <html ng-app="MyModule"> <head> ...

  9. LeetCode Lowest Common Ancestor of a Binary Tree

    原题链接在这里:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ 题目: Given a binary tr ...

  10. LeetCode Basic Calculator II

    原题链接在这里:https://leetcode.com/problems/basic-calculator-ii/ Implement a basic calculator to evaluate ...