在android開(kāi)發(fā)中,怎樣動(dòng)態(tài)生成多界面?
效果:layout界面布局:[html]viewplaincopyprintxmlversion1.0encodingutf-8LinearLayoutxmlns:ad_widthmatch_parentad:layout_heightmatch_parentad:orientationverticalLinearLayoutad:layout_widthmatch_parentad:layout_height30dpad:/titlebar_bgad:orientationhorizontalImageViewad:layout_widthwrap_contentad:layout_heightwrap_contentad:/back_44_44/LinearLayoutad:layout_widthmatch_parentad:layout_height30dpad:gravitycenterTextViewad:layout_widthwrap_contentad:layout_heightwrap_contentad:text課程列表ad:textSize20sp//LinearLayout/LinearLayoutScrollViewad:id@id/ScrollViewad:layout_widthfill_parentad:layout_heightwrap_contentad:scrollbarsverticalLinearLayoutad:id@id/mainLayoutad:layout_widthmatch_parentad:layout_heightwrap_contentad:orientationvertical/LinearLayout/ScrollView/LinearLayouthttputil輔助類(lèi):
[java]viewplaincopyprintpackage;import;import;import;import;import;import;import;importandroid.util.Log;publicclassHttpUtil{publicstaticInputStreamgetInputStream(Stringpath){HttpURLConnectionconnnull;try{URLurlnewURL(path);conn(HttpURLConnection)();(true);//設(shè)置是否向httpUrlConnection輸出,post請(qǐng)求,參數(shù)要放在http正文內(nèi)(true);(3000);(3000);(false);(POST);if(()200){Log.d(mylog,getResponseCode:200);return();}}catch(IOExceptione){();}finally{if(conn!null){conn.disconnect();}}returnnull;}publicstaticStringgetResponseBody(Stringpath,Stringparams){HttpURLConnectionconnnull;StringBufferresultnewStringBuffer()
;try{URLurlnewURL(path);conn(HttpURLConnection)();(true);//設(shè)置是否向httpUrlConnection輸出,post請(qǐng)求,參數(shù)要放在http正文內(nèi)(true);(3000);(3000);(false);(POST);//數(shù)據(jù)輸出流,該語(yǔ)句隱含的執(zhí)行connect動(dòng)作if(params!null){DataOutputStreamoutnewDataOutputStream(());//將參數(shù)寫(xiě)入流,刷新提交關(guān)閉流out.writeBytes(params);out.flush();();}//讀取連接返回的數(shù)據(jù)BufferedReaderreadernewBufferedReader(newInputStreamReader(()));StringinputLinenull;while(((inputLine())!null)){(inputLine);//
;}//關(guān)閉();if(()200){Log.d(mylog,getResponseCode:200);}}catch(IOExceptione){();}finally{if(conn!null){conn.disconnect();}}return();}}主activity:[java]viewplaincopyprintpackage;importorg.json.JSONArray;importorg.json.JSONException;importorg.json.JSONObject;import;import;import;importandroid.os.Bundle;importandroid.util.Log;importandroid.util.TypedValue;import;import;import;import;import;import;importandroid.widget.TextView;publicclassHomeWork4extendsActivity{Stringpath此處省略,你要請(qǐng)求的地址;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView();LinearLayoutmainLayout(LinearLayout)findViewById();Stringresult(path,null);//Log.d(mylog,result:result);try{JSonObjectobjnewJSONObject(result);JSonArrayarray(onlineCourses);for(inti0;iarray.length();i){JSonObjectcourse(i);//Log.d(mylog,course:());//添加左邊的layoutLinearLayoutleftlayoutnewlinearLayout(this);//注意包,其它包下面的LayoutParams不起作用LayoutParamsparamsnewLayoutParams(_PARENT,_CONTENT);;(params);(LinearLayout.HORIZONTAL);(_VERTICAL);//添加左邊layout的圖片ImageViewimageViewnewImageView(this);paramsnewLayoutParams(_CONTENT,_CONTENT);(params);(_default_195_130);(imageView);//添加右邊的layout,分為上下2部分,上面是標(biāo)題,下面是進(jìn)度條LinearLayoutrightlayoutnewlinearLayout(this);LayoutParamsrightLayoutParamsnewLayoutParams(_PARENT,_CONTENT);(rightLayoutParams);();//添加課程標(biāo)題TextViewtextViewnewTextView(this);paramsnewLayoutParams(_CONTENT,_CONTENT);(params);((courseName).toString());(_UNIT_SP,15);//18SP//學(xué)分,水平布局,分為左右,左:學(xué)分,,右:分值LinearLayoutstudyLayoutnewlinearLayout(this);paramsnewLayoutParams(_PARENT,_CONTENT);(params);(LinearLayout.HORIZONTAL);//添加學(xué)分TextViewstudyViewnewTextView(this);paramsnewLayoutParams(_CONTENT,_CONTENT);(params);(學(xué)分:);(_UNIT_SP,12);((#b6b6b6));//第2種方法:setTextColor(Color.rgb(255,255,255));//添加學(xué)分值TextViewstudyValueViewnewTextView(this);paramsnewLayoutParams(_CONTENT,_CONTENT);(params);((courseCredit).toString());(_UNIT_SP,14);//進(jìn)度條,水平布局,分為左中右,左:學(xué)習(xí)進(jìn)度,中:進(jìn)度條,右:%值LinearLayoutprocessLayoutnewlinearLayout(this);paramsnewLayoutParams(_PARENT,_CONTENT);(params);(LinearLayout.HORIZONTAL);//添加學(xué)習(xí)進(jìn)度TextViewprocesstextViewnewTextView(this);paramsnewLayoutParams(_CONTENT,_CONTENT);(params);(學(xué)習(xí)進(jìn)度:);(_UNIT_SP,12);((#b6b6b6));//添加進(jìn)度條ProgressBarbarnewProgressBar(this,null,);//指定進(jìn)度條樣式paramsnewLayoutParams(150,_CONTENT);(params);(100);(10);//添加%值TextViewprocessvaluetextViewnewTextView(this);paramsnewLayoutParams(_CONTENT,_CONTENT);(params);(10%);(_UNIT_SP,12);((#b6b6b6));//添加標(biāo)題(textView);//添加學(xué)分(studyView);(studyValueView);(studyLayout);//添加進(jìn)度條(processtextView);(bar);(processvaluetextView);(processLayout);//添加左右邊(rightlayout);(leftlayout);}}catch(JSONExceptione){();
dw中spanclass怎么添加?
在標(biāo)簽上添加class屬性或者id屬性,比如啊,
或者
在css文件中id選擇器(唯一不可重復(fù)使用)#red{樣式;}class類(lèi)選擇器.center{樣式;}