课程表的实现

主要是使用ScrollView和LinearLayout来实现,比较简单

下面是效果图

activity布局

<?xml version="1.0" encoding="utf-8"?>
<!-- 定义ScrollView,为里面的组件添加垂直滚动条 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="0.5"
            android:gravity="center"
            android:text="7月"
            android:textColor="#ffffff"
            android:textSize="10sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="1"
            android:gravity="center"
            android:text="星期一"
            android:textColor="#ffffff"
            android:textSize="10sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="1"
            android:gravity="center"
            android:text="星期二"
            android:textColor="#ffffff"
            android:textSize="10sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="1"
            android:gravity="center"
            android:text="星期三"
            android:textColor="#ffffff"
            android:textSize="10sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="1"
            android:gravity="center"
            android:text="星期四"
            android:textColor="#ffffff"
            android:textSize="10sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="1"
            android:gravity="center"
            android:text="星期五"
            android:textColor="#ffffff"
            android:textSize="10sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="1"
            android:gravity="center"
            android:text="星期六"
            android:textColor="#ffffff"
            android:textSize="10sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="1"
            android:gravity="center"
            android:text="星期日"
            android:textColor="#ffffff"
            android:textSize="10sp" />
    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fadingEdge="none"
        android:scrollbars="none"
        android:overScrollMode="never" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:orientation="vertical" >

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="50dp"
                    android:gravity="center"
                    android:text="1"
                    android:textColor="#666666"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="50dp"
                    android:gravity="center"
                    android:text="2"
                    android:textColor="#666666"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="50dp"
                    android:gravity="center"
                    android:text="3"
                    android:textColor="#666666"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="50dp"
                    android:gravity="center"
                    android:text="4"
                    android:textColor="#666666"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="50dp"
                    android:gravity="center"
                    android:text="5"
                    android:textColor="#666666"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="50dp"
                    android:gravity="center"
                    android:text="6"
                    android:textColor="#666666"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="50dp"
                    android:gravity="center"
                    android:text="7"
                    android:textColor="#666666"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="50dp"
                    android:gravity="center"
                    android:text="8"
                    android:textColor="#666666"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="50dp"
                    android:gravity="center"
                    android:text="9"
                    android:textColor="#666666"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="50dp"
                    android:gravity="center"
                    android:text="10"
                    android:textColor="#666666"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="50dp"
                    android:gravity="center"
                    android:text="11"
                    android:textColor="#666666"
                    android:textSize="12sp" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="50dp"
                    android:gravity="center"
                    android:text="12"
                    android:textColor="#666666"
                    android:textSize="12sp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/ll1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical" />

            <LinearLayout
                android:id="@+id/ll2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical" />

            <LinearLayout
                android:id="@+id/ll3"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical" />

            <LinearLayout
                android:id="@+id/ll4"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical" />

            <LinearLayout
                android:id="@+id/ll5"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical" />

            <LinearLayout
                android:id="@+id/ll6"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical" />

            <LinearLayout
                android:id="@+id/ll7"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>

课程项布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:paddingRight="5dp"
    android:paddingLeft="5dp"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:textSize="12sp"/>
    <TextView
        android:id="@+id/place"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:textSize="10sp"/>
    <TextView
        android:id="@+id/last"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"
        android:textColor="#ffffff"
        android:textSize="10sp"/>
    <TextView
        android:id="@+id/time"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="13dp"
        android:singleLine="true"
        android:ellipsize="end"
        android:textColor="#ffffff"
        android:textSize="10sp"/>
</LinearLayout>

逻辑实现

package com.bryan;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class TableDemoActivity extends Activity {
    private int colors[] = {
        Color.rgb(0xee,0xff,0xff),
        Color.rgb(0xf0,0x96,0x09),
        Color.rgb(0x8c,0xbf,0x26),
        Color.rgb(0x00,0xab,0xa9),
        Color.rgb(0x99,0x6c,0x33),
        Color.rgb(0x3b,0x92,0xbc),
        Color.rgb(0xd5,0x4d,0x34),
        Color.rgb(0xcc,0xcc,0xcc)
    };

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //分别表示周一到周日
        LinearLayout ll1 = (LinearLayout)findViewById(R.id.ll1);
        LinearLayout ll2 = (LinearLayout)findViewById(R.id.ll2);
        LinearLayout ll3 = (LinearLayout)findViewById(R.id.ll3);
        LinearLayout ll4 = (LinearLayout)findViewById(R.id.ll4);
        LinearLayout ll5 = (LinearLayout)findViewById(R.id.ll5);
        LinearLayout ll6 = (LinearLayout)findViewById(R.id.ll6);
        LinearLayout ll7 = (LinearLayout)findViewById(R.id.ll7);
        //每天的课程设置
        setNoClass(ll1, 2, 0);
        setClass(ll1, "windows编程实践", "国软  4-503", "1-9周,每一周", "9:50-11:25", 2, 1);
        setNoClass(ll1, 3, 0);
        setClass(ll1, "概率论与数理统计", "国软  4-304", "1-15周,每一周", "14:55-17:25", 3, 2);
        setNoClass(ll1, 2, 0);

        setClass(ll2, "大学英语", "国软 4-302", "1-18周,每一周", "8:00-9:35", 2, 3);
        setClass(ll2, "计算机组织体系与结构", "国软 4-204", "1-15,每一周", "9:50-12:15", 3, 5);
        setNoClass(ll2, 3, 0);
        setClass(ll2, "团队激励和沟通", "国软 4-204", "1-9周,每一周", "15:45-17:25", 2, 6);
        setNoClass(ll2, 2, 0);

        setNoClass(ll3, 2, 0);
        setClass(ll3, "中国近现代史纲要", "3区 1-328", "1-9周,每一周", "9:50-12:15", 3, 1);
        setNoClass(ll3, 1, 0);
        setClass(ll3, "体育(网球)", "信息学部 操场", "6-18周,每一周", "14:00-15:40", 2, 2);
        setNoClass(ll3, 4, 0);

        setClass(ll4, "计算机组织体系与结构", "国软 4-204", "1-15,每一周", "8:00-9:35", 2, 5);
        setClass(ll4, "数据结构与算法", "国软 4-304", "1-18周,每一周", "9:50-12:15", 3, 4);
        setNoClass(ll4, 1, 0);
        setClass(ll4, "面向对象程序设计(JAVA)", "国软 1-103", "1-18周,每一周", "14:00-16:30", 3, 5);
        setNoClass(ll4, 3, 0);

        setClass(ll5, "c#程序设计", "国软 4-102", "1-9周,每一周", "8:00-9:35", 2, 6);
        setClass(ll5, "大学英语", "国软 4-302", "1-18周,每一周", "9:50-11:25", 2, 3);
        setNoClass(ll5, 2, 0);
        setClass(ll5, "基础物理", "国软 4-304", "1-18周,每一周", "14:00-16:30", 3, 1);
        setNoClass(ll5, 3, 0);

        setNoClass(ll6, 12, 0);

        setNoClass(ll7, 12, 0);

    }
    /**
     * 设置课程的方法
     * @param ll
     * @param title 课程名称
     * @param place 地点
     * @param last 时间
     * @param time 周次
     * @param classes 节数
     * @param color 背景色
     */
    void setClass(LinearLayout ll, String title, String place,
            String last, String time, int classes, int color)
    {
        View view = LayoutInflater.from(this).inflate(R.layout.item,null);
        int height=dip2px(this,classes * 50);   //48
        LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,height);
        view.setLayoutParams(params);
        view.setBackgroundColor(colors[color]);
        ((TextView)view.findViewById(R.id.title)).setText(title);
        ((TextView)view.findViewById(R.id.place)).setText(place);
        ((TextView)view.findViewById(R.id.last)).setText(last);
        ((TextView)view.findViewById(R.id.time)).setText(time);
        //为课程View设置点击的监听器
        view.setOnClickListener(new OnClickClassListener());
        //上下添加部分间隙
      //  TextView blank1 = new TextView(this);
       // TextView blank2 = new TextView(this);
       // blank1.setHeight(dip2px(this,classes));
      //  blank2.setHeight(dip2px(this,classes));
     //   ll.addView(blank1);
        ll.addView(view);
       // ll.addView(blank2);
    }
    /**
     * 设置无课(空百)
     * @param ll
     * @param classes 无课的节数(长度)
     * @param color
     */
    void setNoClass(LinearLayout ll,int classes, int color)
    {
        TextView blank = new TextView(this);
        if(color == 0)
            blank.setMinHeight(dip2px(this,classes * 50));
        else
           blank.setBackgroundColor(colors[color]);
        ll.addView(blank);
    }
    //点击课程的监听器
    class OnClickClassListener implements OnClickListener{

        public void onClick(View v) {
            // TODO Auto-generated method stub
            String title;
            title = (String) ((TextView)v.findViewById(R.id.title)).getText();
            Toast.makeText(getApplicationContext(), "你点击的是:" + title,
                    Toast.LENGTH_SHORT).show();
        }
    }

    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);} /** * 根据手机的分辨率从 px(像素) 的单位 转成为 dp */
    public static int px2dip(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);}

}

主要是设置有课的数量和没课的数量

源码点击下载

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-04 19:53:07

课程表的实现的相关文章

设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1-2的表(一)~表(四)所示。用SQL语句创建四个表并完成相关题目。

表(一)Student (学生表) -- Create table create table STUDENT ( sno VARCHAR2(3) not null, sname VARCHAR2(8) not null, ssex VARCHAR2(2) not null, sbirthday DATE, class VARCHAR2(5) ) tablespace USERS pctfree 10 initrans 1 maxtrans 255; -- Add comments to the

数据库题:学生表,选课表,课程表

设教学数据库中有三个基本表: 学生表 S(S#,SNAME,AGE,SEX),其属性表示学生的学号.姓名.年龄和性别:选课表 SC(S#,C#,GRADE),其属性表示学生的学号.所学课程的课程号和成绩:课程表 C(C#,CNAME,TEACHER),其属性表示课程号.课程名称和任课教师姓名. 下面的题目都是针对上述三个基本表操作的. (1)写出检索全是女同学选修的课程的课程号的SQL语句. select C# from S,SC where S.S#=SC.S# and S.SEX='女' (

课程表

http://www.cnblogs.com/jycboy/p/kcbyl.html 超超boy 超级课程表原理解析(如何获取网页内容) 一直对手机怎么访问网页很好奇,比如网页上填的姓名密码之类的,在手机上怎么填上去,怎么把网页的内容解析完放在手机上.这次就手机访问教务系统举个简单的例子,相信看完你就懂啦,以后就可以随心所欲的解析网页啦. 君欲善其事,必先利其器.首先要准备两个工具:1.HttpWatch(网页数据分析工具,利用它抓取网页内容),2.一个Jar包:Jsoup(解析网页内容).有了

HBase 3、HBase练习题-学生课程表维护与查询

1.建立学生和课程表 要求:学生可以选择多个课程,每个课程可以被多个学生选择. 查询某个学生所选的所有课程列表 查询某个课程,的学生列表 学生可以修改所选的课程 方案:学生与课程之间是多对多关系,那可以建三张表 学生表.课程表.学生课程关系表 查询某个学生所选的所有课程列表:通过学生ID到学生课程表中去匹配RowKey为studentxxx的记录,然后再根据获取到的记录可以得到课程ID(即RowKey_后的部分): 然后再根据课程ID获取到课程的名称等内容: 查询某个课程,的学生列表:通过课程I

学生表 课程表 成绩表 教师表 50个常用sql语句

原文:http://www.cnblogs.com/zengxiangzhan/archive/2009/09/23/1572276.html Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表   create table Student(S# varchar(20),Sname varchar(10),Sage int,Ssex varchar(2)

超级课程表原理解析(如何获取网页内容)

一直对手机怎么访问网页很好奇,比如网页上填的姓名密码之类的,在手机上怎么填上去,怎么把网页的内容解析完放在手机上.这次就手机访问教务系统举个简单的例子,相信看完你就懂啦,以后就可以随心所欲的解析网页啦. 君欲善其事,必先利其器.首先要准备两个工具:1.HttpWatch(网页数据分析工具,利用它抓取网页内容),2.一个Jar包:Jsoup(解析网页内容).有了这两个东西剩下的事就好办啦. 我是大连海事大学的学生就用海事大学的教务系统为例,实现一个简单的课程表App. 先上图:          

局外人看超级课程表

新闻链接:超级课程表再获数千万美元B轮投资:阿里巴巴集团领投,红杉及策源创投继A轮后追投 http://www.36kr.com/p/214287.html 超级课程表B轮阿里资本领投千万美元,我一听到这消息第一反应是阿里真是烧钱. 超级课程表用户群长期不固定且有限,且不管其CEO吹的用户量多少是真是假,大学生全国不到几千万,而且毕业了基本就用户丢失了.这种情况下做长期的粘性社交几乎不可能,只能是在用户上学的那四五年挖掘价值.也就是说,超级课程表必须做到让用户使用它的四年里能够产生价值,那么用户

爬虫再探实战(五)———爬取APP数据——超级课程表【一】

关于爬虫,开始以为只能爬取网页数据,后来知道APP也能抓取.于是,在学校利用空闲时间,耗时两周实现了数据的抓取和简单的数据分析. 目标,抓取超级课程表XX大学(其实是我们大学啦...)学生20000条发帖信息.思路如下: STEP1:为我们的爬虫找到入口 APP请求数据,也是通过网络协议,这样,我们就抓包来定位入口,这里我用的是fiddler.关于设置手机和fiddler的关联,请参考这篇文章. 找到登陆入口为:http://120.55.151.61/V2/StudentSkip/loginC

sql面试题(学生表_课程表_成绩表_教师表)

sql面试题(学生表_课程表_成绩表_教师表) 原帖链接:http://bbs.csdn.net/topics/280002741 表架构 Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表 建表语句 CREATE TABLE student ( s# INT, sname nvarchar(32), sage INT, ssex nvarchar(8)

android课程表的实现

//该代码段主要实现了课程表所要显示的基本布局 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;