2016 - 2024

感恩一路有你

css如何动态添加class 在android开发中,怎样动态生成多界面?

浏览量:2067 时间:2023-04-07 19:16:39 作者:采采

在android开发中,怎样动态生成多界面?

效果:layout界面布局:[html] view plaincopyprintxml version1.0 encodingutf-8LinearLayout xmlns:ad_widthmatch_parentad:layout_heightmatch_parentad:orientationvertical LinearLayoutad:layout_widthmatch_parentad:layout_height30dpad:/titlebar_bgad:orientationhorizontal ImageViewad:layout_widthwrap_contentad:layout_heightwrap_contentad:/back_44_44 /LinearLayoutad:layout_widthmatch_parentad:layout_height30dpad:gravitycenter TextViewad:layout_widthwrap_contentad:layout_heightwrap_contentad:text课程列表ad:textSize20sp //LinearLayout/LinearLayoutScrollViewad:id@ id/ScrollViewad:layout_widthfill_parentad:layout_heightwrap_contentad:scrollbarsvertical LinearLayoutad:id@ id/mainLayoutad:layout_widthmatch_parentad:layout_heightwrap_contentad:orientationvertical /LinearLayout/ScrollView/LinearLayouthttputil辅助类:

[java] view plaincopyprintpackage ;import ;import ;import ;import ;import ;import ;import ;import android.util.Log;public class HttpUtil {/*** 获取到流,自己处理数据* @param path* @return*/public static InputStream getInputStream(String path) {HttpURLConnection conn null;try {URL url new URL(path);conn (HttpURLConnection) ();(true);// 设置是否向httpUrlConnection输出,post请求,参数要放在http正文内(true);(3000);(3000);(false);(POST);if (() 200) {Log.d(mylog, getResponseCode: 200);return ();}} catch (IOException e) {();} finally {if (conn ! null) {conn.disconnect();}}return null;}/*** 直接返回响应体正文* @param path* @return*/public static String getResponseBody(String path,String params) {HttpURLConnection conn null;StringBuffer resultnew StringBuffer()

;try {URL url new URL(path);conn (HttpURLConnection) ();(true);// 设置是否向httpUrlConnection输出,post请求,参数要放在http正文内(true);(3000);(3000);(false);(POST);//数据输出流,该语句隐含的执行connect动作if(params!null){DataOutputStream out new DataOutputStream( ());//将参数写入流,刷新提交关闭流out.writeBytes(params);out.flush();();}//读取连接返回的数据BufferedReader reader new BufferedReader(new InputStreamReader( ()));String inputLine null;while (((inputLine ()) ! null)) {(inputLine);//

;}//关闭();if (() 200) {Log.d(mylog, getResponseCode: 200);}} catch (IOException e) {();} finally {if (conn ! null) {conn.disconnect();}}return ();}}主activity:[java] view plaincopyprintpackage ;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import ;import ;import ;import android.os.Bundle;import android.util.Log;import android.util.TypedValue;import ;import ;import ;import ;import ;import ;import android.widget.TextView;public class HomeWork4 extends Activity {String path 此处省略,你要请求的地址;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView();LinearLayout mainLayout (LinearLayout)findViewById();String result(path,null);// Log.d(mylog, result: result);try{JSONObject obj new JSONObject(result);JSONArray array(onlineCourses);for (int i 0; i array.length(); i ) {JSONObject course (i);// Log.d(mylog, course: ());//添加左边的layoutLinearLayout leftlayoutnew LinearLayout(this);//注意包,其它包下面的LayoutParams不起作用LayoutParams paramsnew LayoutParams(_PARENT, _CONTENT);;(params);(LinearLayout.HORIZONTAL);(_VERTICAL);//添加左边layout的图片ImageView imageViewnew ImageView(this);paramsnew LayoutParams(_CONTENT, _CONTENT);(params);(_default_195_130);(imageView);//添加右边的layout,分为上下2部分,上面是标题,下面是进度条LinearLayout rightlayoutnew LinearLayout(this);LayoutParams rightLayoutParamsnew LayoutParams(_PARENT, _CONTENT);(rightLayoutParams);();//添加课程标题TextView textViewnew TextView(this);paramsnew LayoutParams(_CONTENT, _CONTENT);(params);((courseName).toString());(_UNIT_SP, 15);//18SP//学分,水平布局,分为左右,左:学分,,右:分值LinearLayout studyLayoutnew LinearLayout(this);paramsnew LayoutParams(_PARENT, _CONTENT);(params);(LinearLayout.HORIZONTAL);//添加学分TextView studyViewnew TextView(this);paramsnew LayoutParams(_CONTENT, _CONTENT);(params);(学分:);(_UNIT_SP, 12);((#b6b6b6));//第2种方法:setTextColor(Color.rgb(255, 255, 255));//添加学分值TextView studyValueViewnew TextView(this);paramsnew LayoutParams(_CONTENT, _CONTENT);(params);((courseCredit).toString());(_UNIT_SP, 14);//进度条,水平布局,分为左中右,左:学习进度,中:进度条,右:%值LinearLayout processLayoutnew LinearLayout(this);paramsnew LayoutParams(_PARENT, _CONTENT);(params);(LinearLayout.HORIZONTAL);//添加学习进度TextView processtextViewnew TextView(this);paramsnew LayoutParams(_CONTENT, _CONTENT);(params);(学习进度:);(_UNIT_SP, 12);((#b6b6b6));//添加进度条ProgressBar barnew ProgressBar(this,null,);//指定进度条样式paramsnew LayoutParams(150, _CONTENT);(params);(100);(10);//添加%值TextView processvaluetextViewnew TextView(this);paramsnew LayoutParams(_CONTENT, _CONTENT);(params);(10%);(_UNIT_SP, 12);((#b6b6b6));//添加标题(textView);//添加学分(studyView);(studyValueView);(studyLayout);//添加进度条(processtextView);(bar);(processvaluetextView);(processLayout);//添加左右边(rightlayout);(leftlayout);}}catch(JSONException e){(); 

dw中span class怎么添加?

在标签上添加class属性或者id属性,比如啊,

或者

在css文件中 id选择器(唯一不可重复使用) #red {样式;} class类选择器 .center {样式;}

layout params paramsnew LayoutParams contentad

版权声明:本文内容由互联网用户自发贡献,本站不承担相关法律责任.如有侵权/违法内容,本站将立刻删除。