运行以下代码,生成dimens文件
public class GenerateDimenTool {
public static void main(String[] args) {
StringBuilder builder = new StringBuilder();
String xmlStart = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n <resources>\n";
builder.append(xmlStart);
for (int i = 0; i <= 300; i++) {
String dimenName = " <dimen name=\"dp" + i + "\">";
String end = "dp</dimen>";
builder.append(dimenName).append(i).append(end).append("\n");
}
builder.append("\n\n\n<!--sp-->\n");
for (int i = 1; i <= 50; i++) {
String dimenName = " <dimen name=\"sp" + i + "\">";
String end = "sp</dimen>";
builder.append(dimenName).append(i).append(end).append("\n");
}
builder.append("</resources>");
String dimensFile = "./basicres/src/main/res/values/dimens.xml";
PrintWriter out = null;
try {
out = new PrintWriter(new BufferedWriter(new FileWriter(dimensFile)));
out.println(builder);
} catch (IOException e) {
e.printStackTrace();
}
out.close();
}
}
ScreenMatch插件生成不同分辨率下的dimens
生成规则在screenMatch.properties 中进行配置
|