在android开发中,怎样动态生成多界面?
效果: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辅助类:
[java]viewplaincopyprintpackage;import;import;import;import;import;import;import;importandroid.util.Log;publicclassHttpUtil{publicstaticInputStreamgetInputStream(Stringpath){HttpURLConnectionconnnull;try{URLurlnewURL(path);conn(HttpURLConnection)();(true);//设置是否向httpUrlConnection输出,post请求,参数要放在http正文内(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);//设置是否向httpUrlConnection输出,post请求,参数要放在http正文内(true);(3000);(3000);(false);(POST);//数据输出流,该语句隐含的执行connect动作if(params!null){DataOutputStreamoutnewDataOutputStream(());//将参数写入流,刷新提交关闭流out.writeBytes(params);out.flush();();}//读取连接返回的数据BufferedReaderreadernewBufferedReader(newInputStreamReader(()));StringinputLinenull;while(((inputLine())!null)){(inputLine);//
;}//关闭();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此处省略,你要请求的地址;@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部分,上面是标题,下面是进度条LinearLayoutrightlayoutnewlinearLayout(this);LayoutParamsrightLayoutParamsnewLayoutParams(_PARENT,_CONTENT);(rightLayoutParams);();//添加课程标题TextViewtextViewnewTextView(this);paramsnewLayoutParams(_CONTENT,_CONTENT);(params);((courseName).toString());(_UNIT_SP,15);//18SP//学分,水平布局,分为左右,左:学分,,右:分值LinearLayoutstudyLayoutnewlinearLayout(this);paramsnewLayoutParams(_PARENT,_CONTENT);(params);(LinearLayout.HORIZONTAL);//添加学分TextViewstudyViewnewTextView(this);paramsnewLayoutParams(_CONTENT,_CONTENT);(params);(学分:);(_UNIT_SP,12);((#b6b6b6));//第2种方法:setTextColor(Color.rgb(255,255,255));//添加学分值TextViewstudyValueViewnewTextView(this);paramsnewLayoutParams(_CONTENT,_CONTENT);(params);((courseCredit).toString());(_UNIT_SP,14);//进度条,水平布局,分为左中右,左:学习进度,中:进度条,右:%值LinearLayoutprocessLayoutnewlinearLayout(this);paramsnewLayoutParams(_PARENT,_CONTENT);(params);(LinearLayout.HORIZONTAL);//添加学习进度TextViewprocesstextViewnewTextView(this);paramsnewLayoutParams(_CONTENT,_CONTENT);(params);(学习进度:);(_UNIT_SP,12);((#b6b6b6));//添加进度条ProgressBarbarnewProgressBar(this,null,);//指定进度条样式paramsnewLayoutParams(150,_CONTENT);(params);(100);(10);//添加%值TextViewprocessvaluetextViewnewTextView(this);paramsnewLayoutParams(_CONTENT,_CONTENT);(params);(10%);(_UNIT_SP,12);((#b6b6b6));//添加标题(textView);//添加学分(studyView);(studyValueView);(studyLayout);//添加进度条(processtextView);(bar);(processvaluetextView);(processLayout);//添加左右边(rightlayout);(leftlayout);}}catch(JSONExceptione){();
dw中spanclass怎么添加?
在标签上添加class属性或者id属性,比如啊,
或者
在css文件中id选择器(唯一不可重复使用)#red{样式;}class类选择器.center{样式;}