Android to implement a simple curriculum
Last Update:2015-05-28
Source: Internet
Author: User
<span id="Label3"></p><p><p>Curriculum to do complex to consider a lot of things, here is only a simple way to implement the Interface: ScrollView nested seven (seven days a week) linearlayout, and each linearlayout can be encapsulated into a curriculum view of the viewitem, are inherited from Framelayout. The following code:</p></p><p><p>The first is the curriculum every day of item, now the default day is 7 lessons, can be set to expand in the code to implement, here now in the XML write dead:</p></p><p><p><span style="white-space:pre"></span></p></p><pre name="code" class="html"><?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=" wrap_content "android:orientation=" Vertical " > <textview android:id= "@+id/tv_school_timetable_item_day" android:layout_width= "match_parent" android:layout_height= "40dp" android:text= "Mon" android:textcolor= "@color/white" android:back ground= "@color/black" android:gravity= "center" android:textsize= "20sp"/> <textview android:id= "@+id/tv_school_timetable_item_class1" android:layout_width= "match_parent" Android:layout_hei ght= "60dp" android:text= "chinese" android:textcolor= "@color/black" android:background= "@color/white" android:gravity= "center" android:textsize= "18sp"/> <textview android:id= "@+i D/tv_school_timetable_item_class2 " Android:layout_width= "match_parent" android:layout_height= "60dp" android:text= "chinese" Android:tex tcolor= "@color/black" android:background= "@color/white" android:gravity= "center" android:textsize= "18 SP "android:layout_margintop=" 1DP "/> <textview android:id=" @+id/tv_school_timetable_it EM_CLASS3 "android:layout_width=" match_parent "android:layout_height=" 60dp "android:text=" Chinese " android:textcolor= "@color/black" android:background= "@color/white" android:gravity= "center" android:t extsize= "18sp" android:layout_margintop= "1dp"/> <textview android:id= "@+id/tv_school_t IMETABLE_ITEM_CLASS4 "android:layout_width=" match_parent "android:layout_height=" 60dp "android:text=" Chinese "android:textcolor=" @color/black "android:background=" @color/white "android:gravity=" Center " Android:textsize= "18SP"android:layout_margintop=" 1dp "/> <textview android:id=" @+id/tv_school_timetable_item _CLASS5 "android:layout_width=" match_parent "android:layout_height=" 60dp "android:text=" language "an" droid:textcolor= "@color/black" android:background= "@color/white" android:gravity= "center" Android:tex tsize= "18sp" android:layout_margintop= "1dp"/> <textview android:id= "@+id/tv_school_tim ETABLE_ITEM_CLASS6 "android:layout_width=" match_parent "android:layout_height=" 60dp "android:text=" Chinese "android:textcolor=" @color/black "android:background=" @color/white "android:gravity=" Center " android:textsize= "18sp" android:layout_margintop= "1dp"/> <textview android:id= "@+id/tv _SCHOOL_TIMETABLE_ITEM_CLASS7 "android:layout_width=" match_parent "android:layout_height=" 60dp "andro id:text= "chinese" Androidoid:textcolor= "@color/black" android:background= "@color/white" android:gravity= "center" android:texts ize= "18sp" android:layout_margintop= "1dp"/></linearlayout></pre>is the vertical row 8 textview, The first text to display the day of the week, followed by the display of the course name, if complex, you can change the TextView to a layout containing multiple view, size can be controlled by the code, here does not expand. Then the code for the item control:<p><p></p></p><p><p></p></p><pre name="code" class="java">Package Com.amuro.timetable;import Com.amuro.schooltimetabletest.r;import Android.content.context;import Android.util.attributeset;import Android.view.layoutinflater;import Android.widget.framelayout;import Android.widget.textview;public class Schooltimetableitem extends Framelayout{private TextView textviewday;private TextView textviewclass1;private TextView textviewclass2;private TextView textviewclass3;private TextView Textviewclass4;private TextView textviewclass5;private TextView textviewclass6;private TextView textViewClass7; Public Schooltimetableitem (context context, attributeset attrs) {super (context, attrs); Layoutinflater.from (context). Inflate (r.layout.school_timetable_item_layout, this); initview ();} private void Initview () {textviewday = (TextView) Findviewbyid (r.id.tv_school_timetable_item_day); textViewClass1 = ( TextView) Findviewbyid (r.id.tv_school_timetable_item_class1); textViewClass2 = (TextView) Findviewbyid (r.id.tv_ school_timetable_item_class2); TEXTVIEWCLASS3 = (TextView) FindViewbyid (r.id.tv_school_timetable_item_class3); textViewClass4 = (TextView) Findviewbyid (r.id.tv_school_timetable_ item_class4); textViewClass5 = (TextView) Findviewbyid (r.id.tv_school_timetable_item_class5); textViewClass6 = ( TextView) Findviewbyid (r.id.tv_school_timetable_item_class6); textViewClass7 = (TextView) Findviewbyid (r.id.tv_ school_timetable_item_class7);} public void Setday (String Day) {textviewday.settext (day);} public void setclasses (string[] classes) {textviewclass1.settext (classes[0]); textviewclass2.settext (classes[1]); Textviewclass3.settext (classes[2]); Textviewclass4.settext (classes[3]); Textviewclass5.settext (classes[4]); Textviewclass6.settext (classes[5]); Textviewclass7.settext (classes[6]);}}</pre>The code is a little low, you can use list to simplify, do not care about these Details.<p><p></p></p><p><p>The next step is to encapsulate the code and layout files into a curriculum control:</p></p><p><p></p></p><pre name="code" class="java">Package Com.amuro.timetable;import Android.content.context;import Android.util.attributeset;import Android.view.layoutinflater;import Android.widget.framelayout;import Com.amuro.schooltimetabletest.r;public Class Schooltimetable extends framelayout{private string[] days = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};p rivate stri ng[][] classes = {{"language", "", "number", "", "", "english", ""}, {"object", "", "", "english", "", "", "", "", "", "", "," "," "," "," "," "," "," "," "," "," "," Language "," "," number "}, {" "," object "," "", "english", "", "", "" "}, {" "," "", "", "", "", "" ""}, "" "," "", "", "" "," "," "," "" Public schooltimetable (context context, attributeset attrs) {super (context, attrs); Layoutinflater.from (context). Inflate (r.layout.school_timetable_layout, this); initview ();} private void Initview () {int startid = r.id.sti_school_timetable_1;for (int i = 0;i < 7;i++) {schooltimetableitem sti = (S Chooltimetableitem) Findviewbyid (startid + i); sti.setday (days[i]); sti.setclasses (classes[i]);}}}</pre><pre name="code" class="html"><?xml version= "1.0" encoding= "utf-8"? ><scrollview xmlns:android= "http://schemas.android.com/apk/res/ Android "android:layout_width=" match_parent "android:layout_height=" wrap_content "> <linearlayout Android:layout_width= "match_parent" android:layout_height= "wrap_content" Android:orientati on= "horizontal" > <com.amuro.timetable.schooltimetableitem android:id= "@+id/sti_school_ti Metable_1 "android:layout_width=" 0dp "android:layout_height=" wrap_content "an droid:layout_weight= "1"/> <com.amuro.timetable.schooltimetableitem android:id= "@+id/sti_school_timetable_2" android:layout_width= "0dp" Android:layout_hei ght= "wrap_content" android:layout_weight= "1" android:layout_marginleft= "1dp" /> <com.Amuro.timetable.SchoolTimetableItem android:id= "@+id/sti_school_timetable_3" Android:layout _width= "0dp" android:layout_height= "wrap_content" android:layout_weight= "1" A ndroid:layout_marginleft= "1dp"/> <com.amuro.timetable.schooltimetableitem android:id= "@+id/sti_school_timetable_4" android:layout_width= "0dp" android:lay out_height= "wrap_content" android:layout_weight= "1" android:layout_marginleft= "1dp" /> <com.amuro.timetable.schooltimetableitem android:id= "@+id/sti_schoo L_timetable_5 "android:layout_width=" 0dp "android:layout_height=" wrap_content " android:layout_weight= "1" android:layout_marginleft= "1dp"/> < ; com.amuro.timetable.SchOoltimetableitem android:id= "@+id/sti_school_timetable_6" android:layout_width= "0dp" android:layout_height= "wrap_content" android:layout_weight= "1" android:layout_margi nleft= "1dp"/> <com.amuro.timetable.schooltimetableitem Androi d:id= "@+id/sti_school_timetable_7" android:layout_width= "0dp" android:layout_height= "wrap_co Ntent "android:layout_weight=" 1 "android:layout_marginleft=" 1dp "/> </LinearLayout></ScrollView></pre><br>The curriculum and curriculum item is separated for each side can expand the function, do a good decoupling, familiar with my friends know this is even obsessive-compulsive disorder.<p><p></p></p><p><p>finally, Many friends will certainly say:</p></p><p><p><br><br>Since you've all said that, I'm not going to go, thank you all, escape ~</p></p><p><p>Android to implement a simple curriculum</p></p></span>