drawable xml绘图简单用法?新建Android项目layout文件下的两个XML文件的用法

本文目录
drawable xml绘图简单用法
drawable里的xml文件做绘图资源非常方便,不需要适配屏幕dpi,几个比较简单的用法:
sharp是比较常用的drawable,可以绘制line、oval、rectangle和 ring。以sharp为例绘制一个红色椭圆和蓝色圆环。
预览下:
接着画一个外环宽度为8dp的圆环
故名思议,layer-list就是图层,把几个可绘制的drawable排列起来,layer-list最下边的item会放置在最上层,我们把之前的红色圆形和蓝色环形重叠起来,绘制一个带蓝边的红圆。
预览:
state-list是根据对象的状态分别绘制不同的图形,比如的是绘制一个圆形按钮,平时是红色,按下时是蓝色。
需要注意的是,按下状态的item要写在通常状态之前。把这个xml文件设置一个button的background,就可以使用了。
***隐藏网址***
新建Android项目layout文件下的两个XML文件的用法
1.现在新建一个Android工程,在Layout文件夹里面会新建两个XML的文件,两个分别是activity_main.xml和fragment_main.xml,
2.在默认情况下,试图运行一下方法,总是会出错,
3.解决方法,
首先,把onCreate()方法中的activity_main换成fragment_main,
然后,把下面的if()语句注释掉,
再尝试运行,就没有问题了。
asp.net(c#) 中xml具体用法
asp.net创建xml就是通过创建DataTable来创建xml中的树型等
1 DataSet objset=new DataSet();
2 DataTable istable=new DataTable("test");
3 istable.Columns.Add("rate1",typeof(int));
4 istable.Columns.Add("rate2",typeof(int));
5 istable.Columns.Add("rate3",typeof(int));
6 istable.Columns.Add("rate4",typeof(int));
7 objset.Tables.Add(istable);
8
9 DataRow dr=objset.Tables.NewRow();
10 dr=赋值;
11 dr=赋值;
12 dr=赋值;
13 dr=赋值;
14 objset.Tables.Rows.Add(dr);
15
16 objset.WriteXml(Server.MapPath("test.xml"),XmlWriteMode.WriteSchema);
其中就是先创建DataSet和DataTable,其中建立的表为test,再在表中添加子项rate1,2,3,4,再定义新的行,分别添加对应的值,最后这些都已经写进DataSet表中,通过DataSet把xml输入就完成了。要读就只需要把xml的数据读到DataSet中,再通过 DataSet中的表的项来对应读出数据。
而C#中则使用的DOM来实现操作,比如现有一个bookstore.xml文件,内容如下
《?xml version="1.0" encoding="gb2312"?》
《bookstore》
《book genre="fantasy" ISBN="2-3631-4"》
《title》Oberon’s Legacy《/title》
《author》Corets, Eva《/author》
《price》5.95《/price》
《/book》
《/bookstore》
下面讲解4种常用的方法
1、往《bookstore》节点中插入一个《book》节点:
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load("bookstore.xml");
XmlNode root=xmlDoc.SelectSingleNode("bookstore");//查找《bookstore》
XmlElement xe1=xmlDoc.CreateElement("book");//创建一个《book》节点
xe1.SetAttribute("genre","李赞红");//设置该节点genre属性
xe1.SetAttribute("ISBN","2-3631-4");//设置该节点ISBN属性
XmlElement xesub1=xmlDoc.CreateElement("title");
xesub1.InnerText="CS从入门到精通";//设置文本节点
xe1.AppendChild(xesub1);//添加到《book》节点中
XmlElement xesub2=xmlDoc.CreateElement("author");
xesub2.InnerText="候捷";
xe1.AppendChild(xesub2);
XmlElement xesub3=xmlDoc.CreateElement("price");
xesub3.InnerText="58.3";
xe1.AppendChild(xesub3);
root.AppendChild(xe1);//添加到《bookstore》节点中
xmlDoc.Save("bookstore.xml");
//================
结果为:
《?xml version="1.0" encoding="gb2312"?》
《bookstore》
《book genre="fantasy" ISBN="2-3631-4"》
《title》Oberon’s Legacy《/title》
《author》Corets, Eva《/author》
《price》5.95《/price》
《/book》
《book genre="李赞红" ISBN="2-3631-4"》
《title》CS从入门到精通《/title》
《author》候捷《/author》
《price》58.3《/price》
《/book》
《/bookstore》
2、修改节点:将genre属性值为“李赞红“的节点的genre值改为“update李赞红”,将该节点的子节点《author》的文本修改为“亚胜”。
XmlNodeList nodeList=xmlDoc.SelectSingleNode("bookstore").ChildNodes;//获取bookstore节点的所有子节点
foreach(XmlNode xn in nodeList)//遍历所有子节点
{
XmlElement xe=(XmlElement)xn;//将子节点类型转换为XmlElement类型
if(xe.GetAttribute("genre")=="李赞红")//如果genre属性值为“李赞红”
{
xe.SetAttribute("genre","update李赞红");//则修改该属性为“update李赞红”
XmlNodeList nls=xe.ChildNodes;//继续获取xe子节点的所有子节点
foreach(XmlNode xn1 in nls)//遍历
{
XmlElement xe2=(XmlElement)xn1;//转换类型
if(xe2.Name=="author")//如果找到
{
xe2.InnerText="亚胜";//则修改
break;//找到退出来就可以了
}
}
break;
}
}
xmlDoc.Save("bookstore.xml");//保存。
//=================
最后结果为:
《?xml version="1.0" encoding="gb2312"?》
《bookstore》
《book genre="fantasy" ISBN="2-3631-4"》
《title》Oberon’s Legacy《/title》
《author》Corets, Eva《/author》
《price》5.95《/price》
《/book》
《book genre="update李赞红" ISBN="2-3631-4"》
《title》CS从入门到精通《/title》
《author》亚胜《/author》
《price》58.3《/price》
《/book》
《/bookstore》
3、删除 《book genre="fantasy" ISBN="2-3631-4"》节点的genre属性,删除 《book genre="update李赞红" ISBN="2-3631-4"》节点。
XmlNodeList xnl=xmlDoc.SelectSingleNode("bookstore").ChildNodes;
foreach(XmlNode xn in xnl)
{
XmlElement xe=(XmlElement)xn;
if(xe.GetAttribute("genre")=="fantasy")
{
xe.RemoveAttribute("genre");//删除genre属性
}
else if(xe.GetAttribute("genre")=="update李赞红")
{
xe.RemoveAll();//删除该节点的全部内容
}
}
xmlDoc.Save("bookstore.xml");
//====================
最后结果为:
《?xml version="1.0" encoding="gb2312"?》
《bookstore》
《book ISBN="2-3631-4"》
《title》Oberon’s Legacy《/title》
《author》Corets, Eva《/author》
《price》5.95《/price》
《/book》
《book》
《/book》
《/bookstore》
4、显示所有数据。
XmlNode xn=xmlDoc.SelectSingleNode("bookstore");
XmlNodeList xnl=xn.ChildNodes;
foreach(XmlNode xnf in xnl)
{
XmlElement xe=(XmlElement)xnf;
Console.WriteLine(xe.GetAttribute("genre"));//显示属性值
Console.WriteLine(xe.GetAttribute("ISBN"));
XmlNodeList xnf1=xe.ChildNodes;
foreach(XmlNode xn2 in xnf1)
{
Console.WriteLine(xn2.InnerText);//显示子节点点文本
}
}
以上的就是ASP.NET和C#对xml的基本使用方法。下面说一下xml和xsl,从抽象的来说,我个人觉得xml象是数据库,而xsl就象是过滤的。xsl中可以加入html等语法,也可以加入xml的语法等,可以列出需要的数据等。
现有一个xml文件,内容如下
《?xml version="1.0"?》
《?xml-stylesheet type="text/xsl" href="test.xsl"?》
《NewDataSet》
《Table id="1"》
《ProductID》1001《/ProductID》
《CategoryID》1《/CategoryID》
《/Table》
《Table id="2"》
《ProductID》1002《/ProductID》
《CategoryID》2《/CategoryID》
《/Table》
《/NewDataSet》
其中第2句是引用xsl,xsl内容如下
《?xml version="1.0"?》
***隐藏网址***
《xsl:template match="/"》
《html》
《body》
《center》
《h3》the notepad《/h3》
《table border="1"》
《tr》
《td》id《/td》
《td》name《/td》
《/tr》
《xsl:for-each select="NewDataSet/Table"》
《tr》
《td》《xsl:value-of select="ProductID"/》《/td》
《td》《xsl:value-of select="ProductName"/》《/td》
《/tr》
《/xsl:for-each》
《/table》
《/center》
《/body》
《/html》
《/xsl:template》
《/xsl:stylesheet》
中间的for-each就是循环遍历节点,获取指定的select后的内容,下面的value-of就相当于sql中字段名。在使用xsl的时候,还可以查询某一个值,这样xsl就需要如下《xsl:value-of select="/students/student/ProductID"/》
《?xml version="1.0" encoding="gb2312"?》
***隐藏网址***
《xsl:template match="/"》
《center》 《h1》id号是"2"的厂家的产品ID是:《xsl:value-of select="/NewDataSet/Table/ProductID"/》《/h1》《/center》
《/xsl:template》
《/xsl:stylesheet》
有些如果在Table下还有节点,要显示这个节点下的东西xsl就该如下
《?xml version="1.0"?》
***隐藏网址***
《xsl:template match="/"》
《html》
《body》
《center》
《h3》the notepad《/h3》
《table border="1"》
《tr》
《td》随便写《/td》
《/tr》
《xsl:for-each select="NewDataSet/Table/xx/*"》
《tr》
《td》《xsl:value-of select="."/》《/td》
《/tr》
《/xsl:for-each》
《/table》
《/center》
《/body》
《/html》
《/xsl:template》
《/xsl:stylesheet》

更多文章:
login failed(提示C2 NO LOGIN failed.什么意思)
2026年8月24日 02:00
js获取系统当前月份(javascript 里获取当前月份,用2位数表示,怎么整就像1月是 01. 简单的办法我现在用急啊给分)
2025年11月3日 07:15
executor shutdown不生效(我做了一个bat的文件,是设置关机时间的,但为什么不生效呢 哪位高手帮我看下)
2026年5月20日 14:30
he positioned himself at the gate的意思(值得背诵的英语美文3篇)
2025年12月10日 23:30
hadoop启动(hadoop启动namenode提示目录不存在)
2025年9月9日 12:30
subjected翻译(listen和subject的区别)
2026年1月6日 08:30
delphi aes cbc pkcs5加密(AES共有ECB,CBC,CFB,OFB,CTR五种模式分别有什么区别)
2026年4月27日 16:15
















