編輯:關於Android編程
根據提供的課程信息,動態生成課程表。不同於網上流傳的課表形式,課程節數是固定,本課表的課程節數不固定。
1、效果圖
每天共有12節課,上課節數每天都不同。
2、布局文件代碼
周一到周日是 7個豎直線性布局文件,其他皆為輔助標題或序號。
3、布局文件中用到的尺寸文件
4、顏色文件40dp 2dp 2dp
5、樣式文件#CCCCCC #ECECEC #6666CC #EDEDED
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; } }
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; List list2=new ArrayList (); list2.add(new Course(計算機組成原理, A106, 6, 3, 馬超, 1001)); courseData[1]=list2; List list3=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; List list4=new ArrayList (); list4.add(new Course(數據結構, A223, 1, 3, 劉備, 1012)); list4.add(new Course(操作系統, A405, 6, 3, 曹操, 1014)); courseData[3]=list4; List list5=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,List data){ 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; } }
Android應用程序窗口的繪圖表面在創建完成之後,我們就可以從上到下地繪制它裡面的各個視圖了,即各個UI元素了。不過在繪制這些UI元素之前,我們還需要從上到下地測量它們
手勢有三個主要特征:手型,方向,運動軌跡一個基於視覺手勢識別系統的構成應包括:圖像的采集,預處理,特征提取和選擇,分類器的設計,以及手勢識別。其流程大致如下:上面識別過程
最近新參加的項目中使用到了activity的singleInstance 模式並在開發中產生了一些bug,發現組內的同事們對launchmode這件事情還缺少一些基本的認
前言Universal-Image-Loader,android-Volley,Picasso、Fresco和Glide五大Android開源組件加載網絡圖片比較。在An