import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter; public class MakeXml {
private final static String rootPath = "C:\\Users\\Administrator\\Desktop\\layoutroot\\values-{0}x{1}\\"; private final static float dw = 480f;
private final static float dh = 800f; private final static String WTemplate = "<dimen name=\"x{0}\">{1}px</dimen>\n";
private final static String HTemplate = "<dimen name=\"y{0}\">{1}px</dimen>\n"; private final static int[] otherPxX = new int[]{};
private final static int[] otherPxY = new int[]{}; public static void main(String[] args) {
// makeString(320, 480);
makeString(480, 800);
makeString(480, 640);
// makeString(480, 854);
// makeString(540, 960);
// makeString(600, 1024);
// makeString(720, 1184);
// makeString(720, 1196);
// makeString(720, 1280);
// makeString(768, 1024);
// makeString(800, 1280);
// makeString(1080, 1812);
makeString(1080, 1920);
// makeString(1440, 2560);
} public static void makeString(int w, int h) {
StringBuffer sb = new StringBuffer();
sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
sb.append("<resources>");
float cellw = w / dw;
int tempxCount = (int) (dw * 2 / 3);
for (int i = 1; i < tempxCount + 1; i++) {
sb.append(WTemplate.replace("{0}", i + "").replace("{1}",
change(cellw * i) + ""));
} for (int i = 0; i < otherPxX.length; i++) {
int temp = otherPxX[i];
if (temp < dw && temp > tempxCount) {
sb.append(WTemplate.replace("{0}", temp + "").replace("{1}",
change(cellw * temp) + ""));
}
} // sb.append(WTemplate.replace("{0}", "320").replace("{1}", w + ""));
sb.append("</resources>"); StringBuffer sb2 = new StringBuffer();
sb2.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
sb2.append("<resources>");
float cellh = h / dh;
int tempyCount = (int) (dh / 3);
for (int i = 1; i < tempyCount + 1; i++) {
sb2.append(HTemplate.replace("{0}", i + "").replace("{1}",
change(cellh * i) + ""));
} for (int i = 0; i < otherPxY.length; i++) {
int temp = otherPxY[i];
if (temp <= dh && temp > tempyCount) {
sb.append(WTemplate.replace("{0}", temp + "").replace("{1}",
change(cellw * temp) + ""));
}
} // sb2.append(HTemplate.replace("{0}", "480").replace("{1}", h + ""));
sb2.append("</resources>"); String path = rootPath.replace("{0}", w + "").replace("{1}", h + "");
File rootFile = new File(path);
if (!rootFile.exists()) {
rootFile.mkdirs();
}
File layxFile = new File(path + "lay_x.xml");
File layyFile = new File(path + "lay_y.xml");
PrintWriter pw = null;
try {
pw = new PrintWriter(new FileOutputStream(layxFile));
pw.print(sb.toString());
pw.close();
pw = new PrintWriter(new FileOutputStream(layyFile));
pw.print(sb2.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (pw != null)
pw.close();
} } public static float change(float a) {
int temp = (int) (a * 100);
return temp / 100f;
}
}

生成不同尺寸dimen的xml文件以及文件夹的更多相关文章

  1. ASP.NET Core WebApi使用Swagger生成API说明文档【xml注释版】

    ⒈新建ASP.NET Core WebAPi项目 ⒉添加 NuGet 包 Install-Package Swashbuckle.AspNetCore ⒊Startup中配置 using System ...

  2. eclipse或adt-bundle创建的android项目没有自动生成MainActivity.java和activity_main.xml等文件解决办法

    以前我电脑一直以来都是用的eclipse3.7来开发android项目的,创建android项目也能正常生成MainActivity.java和activity_main.xml等文件.后来不知道什么 ...

  3. Python生成PASCAL VOC格式的xml标注文件

    Python生成PASCAL VOC格式的xml标注文件 PASCAL VOC数据集的标注文件是xml格式的.对于py-faster-rcnn,通常以下示例的字段是合适的: <annotatio ...

  4. VisualStudio编译不生成xml、pdb文件的方法

    我们为了减少发布/Release时项目的体积,希望在编译时不生成xml注释文档(包括引用的其他类库),和pdb调试文件 用你喜欢的文本编辑器打开项目.csproj文件,找到PropertyGroup节 ...

  5. opencv 3 core组件进阶(3 离散傅里叶变换;输入输出XML和YAML文件)

    离散傅里叶变换 #include "opencv2/core/core.hpp" #include "opencv2/imgproc/imgproc.hpp" ...

  6. Python(文件、文件夹压缩处理模块,shelve持久化模块,xml处理模块、ConfigParser文档配置模块、hashlib加密模块,subprocess系统交互模块 log模块)

    OS模块 提供对操作系统进行调用的接口 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname")  改变当前脚本工作目 ...

  7. Java 通过Xml导出Excel文件,Java Excel 导出工具类,Java导出Excel工具类

    Java 通过Xml导出Excel文件,Java Excel 导出工具类,Java导出Excel工具类 ============================== ©Copyright 蕃薯耀 20 ...

  8. ionic生成全尺寸icon和splash

    http://www.jianshu.com/p/eda363eb28d3 重新添加platform --no-resources可以禁止重新生成icon和splash ionic cordova p ...

  9. Xml日志记录文件最优方案(附源代码)

    Xml作为数据存储的一种方式,当数据非常大的时候,我们将碰到很多Xml处理的问题.通常,我们对Xml文件进行编辑的最直接的方式是将xml文件加载到XmlDocument,在内存中来对XmlDocume ...

随机推荐

  1. JS制作蔡徐坤打篮球小游戏(鸡你太美?)

    一.前提: 和我之前写的 QT小球游戏 差不多(指的是实现方法). 感谢大佬的 Github:https://github.com/kasuganosoras/cxk-ball 外加游戏网页:http ...

  2. IDEA修改显示星号*和热部署

    IDEA修改显示*星号: IDEA热部署: 两步: 1. 2. Ctrl+Alt+Shift+/ 打开下面界面,选Registry 对于Springboot应用,可能无法启动,在上述两步不起作用的情况 ...

  3. MAVEN项目中include引入静态文件时报错找不到文件

    1. 出现的问题 Fragment "/common/jsp/resource.jsp" was not found at expected path /src/main/weba ...

  4. webform运行时弹出JavaScript的alert窗口

    https://stackoverflow.com/questions/9720143/asp-net-web-application-message-box Or create a method l ...

  5. HackerRank-Python攻城歷程-3.List( Find the Second Largest Number )

    if __name__ == '__main__': n = int(input()) arr = map(int, input().split()) print(sorted(list(set(ar ...

  6. C#多线程和线程池

    1.概念  1.0 线程的和进程的关系以及优缺点 windows系统是一个多线程的操作系统.一个程序至少有一个进程,一个进程至少有一个线程.进程是线程的容器,一个C#客户端程序开始于一个单独的线程,C ...

  7. Vue-admin工作整理(一):项目搭建

    1.首先要安装vue-cli 3.0以上版本,和git 该版本可以支持页面化快速创建: sudo npm install -g @vue/cli 安装完毕后查看vue版本信息:vue -V 2.安装好 ...

  8. SSH实现ajax

    (1)首先要引入需要pom文件 <!-- https://mvnrepository.com/artifact/org.apache.struts/struts2-json-plugin --& ...

  9. How Many Zeroes? LightOJ - 1140

    #include<stdio.h> #include<string.h> #include<math.h> #include<time.h> #incl ...

  10. OpenGL.Tutorial15_Lightmaps

    ZC:撤销 & 重做 — Blender Manual.html(https://docs.blender.org/manual/zh-hans/dev/interface/undo_redo ...