在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{/***获取到流,自己处理数据*@parampath*@return*/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;}/***直接返回响应体正文*@parampath*@return*/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{样式;}
原文标题:css如何动态添加class 在android开发中,怎样动态生成多界面?,如若转载,请注明出处:https://www.suhaipipe.com/suhai5/36441.html
免责声明:此资讯系转载自合作媒体或互联网其它网站,「蓝鲸百科」登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,文章内容仅供参考。