生成不同尺寸dimen的xml文件以及文件夹
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文件以及文件夹的更多相关文章
- ASP.NET Core WebApi使用Swagger生成API说明文档【xml注释版】
⒈新建ASP.NET Core WebAPi项目 ⒉添加 NuGet 包 Install-Package Swashbuckle.AspNetCore ⒊Startup中配置 using System ...
- eclipse或adt-bundle创建的android项目没有自动生成MainActivity.java和activity_main.xml等文件解决办法
以前我电脑一直以来都是用的eclipse3.7来开发android项目的,创建android项目也能正常生成MainActivity.java和activity_main.xml等文件.后来不知道什么 ...
- Python生成PASCAL VOC格式的xml标注文件
Python生成PASCAL VOC格式的xml标注文件 PASCAL VOC数据集的标注文件是xml格式的.对于py-faster-rcnn,通常以下示例的字段是合适的: <annotatio ...
- VisualStudio编译不生成xml、pdb文件的方法
我们为了减少发布/Release时项目的体积,希望在编译时不生成xml注释文档(包括引用的其他类库),和pdb调试文件 用你喜欢的文本编辑器打开项目.csproj文件,找到PropertyGroup节 ...
- opencv 3 core组件进阶(3 离散傅里叶变换;输入输出XML和YAML文件)
离散傅里叶变换 #include "opencv2/core/core.hpp" #include "opencv2/imgproc/imgproc.hpp" ...
- Python(文件、文件夹压缩处理模块,shelve持久化模块,xml处理模块、ConfigParser文档配置模块、hashlib加密模块,subprocess系统交互模块 log模块)
OS模块 提供对操作系统进行调用的接口 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目 ...
- Java 通过Xml导出Excel文件,Java Excel 导出工具类,Java导出Excel工具类
Java 通过Xml导出Excel文件,Java Excel 导出工具类,Java导出Excel工具类 ============================== ©Copyright 蕃薯耀 20 ...
- ionic生成全尺寸icon和splash
http://www.jianshu.com/p/eda363eb28d3 重新添加platform --no-resources可以禁止重新生成icon和splash ionic cordova p ...
- Xml日志记录文件最优方案(附源代码)
Xml作为数据存储的一种方式,当数据非常大的时候,我们将碰到很多Xml处理的问题.通常,我们对Xml文件进行编辑的最直接的方式是将xml文件加载到XmlDocument,在内存中来对XmlDocume ...
随机推荐
- 'OFFSET' 附近有语法错误。 在 FETCH 语句中选项 NEXT 的用法无效。
在使用asp.net core的时候,采用take().skip()分页的时候报如下错误: SqlException: 'OFFSET' 附近有语法错误. 在 FETCH 语句中选项 NEXT 的用法 ...
- 问题:Linux报swap空间占用过高,但物理内存还有空余
报错 收到报警,swap空间占用过高,登录到系统查看内存使用详情,看到物理内存还有很多未使用 问题分析 Swap配置对性能的影响分配太多的Swap空间会浪费磁盘空间,而Swap空间太少,则系统会发生错 ...
- pat1003 迪杰斯特拉法和dfs求最短路
本题的背景是求定点和定点之间的最短路问题(所有的最短路 不是一个解 是全部解,方法手段来自数据结构课程中的迪杰斯特拉算法和dfs(深度优先遍历). 分别用两种方法编程如下代码 dfs #includ ...
- 生成式对抗网络(GAN)学习笔记
图像识别和自然语言处理是目前应用极为广泛的AI技术,这些技术不管是速度还是准确度都已经达到了相当的高度,具体应用例如智能手机的人脸解锁.内置的语音助手.这些技术的实现和发展都离不开神经网络,可是传统的 ...
- jquery.validator 手机号验证
1.在input中加上mobile="true",maxlength="11" <label class="w170 control-label ...
- javascript 删除 url 中指定参数,并返回 url
// 删除url中某个参数,并跳转function funcUrlDel(name){ var loca = window.location; var baseUrl = loca.origin + ...
- git1使用步骤初始化拉取修改提交推送
Git 使用 git init 命令来初始化一个 Git 仓库,Git 的很多命令都需要在 Git 的仓库中运行,所以 git init 是使用 Git 的第一个命令. 在执行完成 git init ...
- 自定义Cordova插件(基础篇)
cordova自定义插件 注意:存放自定义cordova插件目录不能有空格可能会报错 cordova的安装 下载node.js,安装完成后你可以在命令行中使用node和npm. 安装cordova使用 ...
- 设置IE浏览器跨域访问数据
在开发中,经常会遇到多站点跨域访问后台服务获取数据的情况,解决方法有两种 自己写代理服务,访问代理服务,代理服务请求服务获取数据再返回: 设置浏览器可以跨域访问数据. 本文来讲如何设置IE浏览器跨域访 ...
- vue中使用动画vue-particles
1.下载依赖 npm install vue-particles --save-dev 2.main.js引入 import Vue from 'vue' import VueParticles fr ...