Android動態產生課程表 詳解

來源:互聯網
上載者:User

Android動態產生課程表 詳解

根據提供的課程資訊,動態產生課程表。不同於網上流傳的課表形式,課程節數是固定,本課表的課程節數不固定。

1、

每天共有12節課,上課節數每天都不同。

2、布局檔案代碼

周一到周日是 7個豎直線性布局檔案,其他皆為輔助標題或序號。

 

          
3、布局檔案中用到的尺寸檔案

 

 

    40dp    2dp    2dp    
4、顏色檔案

 

 

    #CCCCCC    #ECECEC    #6666CC    #EDEDED
5、樣式檔案

 

 

        

6、課程實體類代碼

 

 

package com.example.testcourse;public class Course {private String name,room,teach,id;//課程名稱、上課教室,教師,課程編號int start,step;//開始上課節次, 一共幾節課public Course(String name, String room, int start, int step,String teach, String id) {super();this.name = name;this.room = room;this.start = start;this.step = step;this.teach = teach;this.id = id;}public String getId() {return id;}public void setId(String id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getRoom() {return room;}public void setRoom(String room) {this.room = room;}public int getStart() {return start;}public void setStart(int start) {this.start = start;}public int getStep() {return step;}public void setStep(int step) {this.step = step;}public String getTeach() {return teach;}public void setTeach(String teach) {this.teach = teach;}}

7、Activity代碼,只要提供7天課程資訊,課表可以自動產生。

 

 

package com.example.testcourse;import java.util.ArrayList;import java.util.List;import android.os.Bundle;import android.app.Activity;import android.graphics.Color;import android.text.Layout;import android.util.Log;import android.view.Gravity;import android.view.Menu;import android.widget.LinearLayout;import android.widget.TextView;public class MainActivity extends Activity {LinearLayout weekPanels[]=new LinearLayout[7];List courseData[]=new ArrayList[7];int itemHeight;int marTop,marLeft;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        //        itemHeight=getResources().getDimensionPixelSize(R.dimen.weekItemHeight);        marTop=getResources().getDimensionPixelSize(R.dimen.weekItemMarTop);        marLeft=getResources().getDimensionPixelSize(R.dimen.weekItemMarLeft);                //資料        getData();                for (int i = 0; i < weekPanels.length; i++) {weekPanels[i]=(LinearLayout) findViewById(R.id.weekPanel_1+i);initWeekPanel(weekPanels[i], courseData[i]);}            }    public void getData(){    Listlist1=new ArrayList();    Course c1 =new Course(軟體工程,A402, 1, 4, 典韋, 1002);    list1.add(c1);    list1.add(new Course(C語言, A101, 6, 3, 甘寧, 1001));    courseData[0]=list1;    Listlist2=new ArrayList();    list2.add(new Course(電腦群組成原理, A106, 6, 3, 馬超, 1001));    courseData[1]=list2;        Listlist3=new ArrayList();    list3.add(new Course(資料庫原理, A105, 2, 3, 孫權, 1008));    list3.add(new Course(電腦網路, A405, 6, 2, 司馬懿, 1009));    list3.add(new Course(電影賞析, A112, 9, 2, 諸葛亮, 1039));    courseData[2]=list3;        Listlist4=new ArrayList();    list4.add(new Course(資料結構, A223, 1, 3, 劉備, 1012));    list4.add(new Course(作業系統, A405, 6, 3, 曹操, 1014));    courseData[3]=list4;        Listlist5=new ArrayList();    list5.add(new Course(Android開發,C120,1,4,黃蓋,1250));    list5.add(new Course(遊戲設計原理,C120,8,4,陸遜,1251));    courseData[4]=list5;    }        public void initWeekPanel(LinearLayout ll,Listdata){    if(ll==null || data==null || data.size()<1)return;    Log.i(Msg, 初始化面板);    Course pre=data.get(0);    for (int i = 0; i < data.size(); i++) {Course c =data.get(i);TextView tv =new TextView(this);LinearLayout.LayoutParams lp =new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT ,itemHeight*c.getStep()+marTop*(c.getStep()-1));if(i>0){lp.setMargins(marLeft, (c.getStart()-(pre.getStart()+pre.getStep()))*(itemHeight+marTop)+marTop, 0, 0);}else{lp.setMargins(marLeft, (c.getStart()-1)*(itemHeight+marTop)+marTop, 0, 0);}tv.setLayoutParams(lp);tv.setGravity(Gravity.TOP);tv.setGravity(Gravity.CENTER_HORIZONTAL);tv.setTextSize(12);tv.setTextColor(getResources().getColor(R.color.courseTextColor));tv.setText(c.getName()++c.getRoom()++c.getTeach());//tv.setBackgroundColor(getResources().getColor(R.color.classIndex));tv.setBackground(getResources().getDrawable(R.drawable.tvshape));ll.addView(tv);pre=c;}    }        @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.activity_main, menu);        return true;    }    }





 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.