第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

幫你們解決屏幕適配問題

標簽:
Android

private int baseW;
private int baseH;

private String dirStr = "/.res";

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";

/**
 * {0}-HEIGHT
 */
private final static String VALUE_TEMPLATE = "values-{0}x{1}";

private static final String SUPPORT_DIMESION = "320,480;480,800;480,854;540,960;600,1024;720,1184;720,1196;720,1280;768,1024;800,1280;1080,1812;1080,1920;1440,2560;";

private String supportStr = SUPPORT_DIMESION;

public GenerateValueFiles(int baseX, int baseY, String supportStr) {
    this.baseW = baseX;
    this.baseH = baseY;

    if (!this.supportStr.contains(baseX + "," + baseY)) {
        this.supportStr += baseX + "," + baseY + ";";
    }

    this.supportStr += validateInput(supportStr);

    System.out.println(supportStr);

    File dir = new File(dirStr);
    if (!dir.exists()) {
        dir.mkdir();
    }
}

/**
 * w,h_...w,h;
 * 
 * @param supportStr
 * @return
 */
private String validateInput(String supportStr) {
    StringBuffer sb = new StringBuffer();
    String[] vals = supportStr.split("_");
    int w = -1;
    int h = -1;
    String[] wh;
    for (String val : vals) {
        try {
            if (val == null || val.trim().length() == 0)
                continue;

            wh = val.split(",");
            w = Integer.parseInt(wh[0]);
            h = Integer.parseInt(wh[1]);

        } catch (Exception e) {
            System.out.println("skip invalidate params : w,h = " + val);
            continue;
        }
        sb.append(w + "," + h + ";");
    }
    return sb.toString();
}

public void generate() {
    String[] vals = supportStr.split(";");
    for (String val : vals) {
        String[] wh = val.split(",");
        generateXmlFile(Integer.parseInt(wh[0]), Integer.parseInt(wh[1]));
    }

}

private void generateXmlFile(int w, int h) {

    StringBuffer sbForWidth = new StringBuffer();
    sbForWidth.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
    sbForWidth.append("<resources>");
    float cellw = w * 1.0f / baseW;

    System.out.println("width : " + w + "," + baseW + "," + cellw);
    for (int i = 1; i < baseW; i++) {
        sbForWidth.append(WTemplate.replace("{0}", i + "").replace("{1}",
                change(cellw * i) + ""));
    }
    sbForWidth.append(WTemplate.replace("{0}", baseW + "").replace("{1}",
            w + ""));
    sbForWidth.append("</resources>");

    StringBuffer sbForHeight = new StringBuffer();
    sbForHeight.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
    sbForHeight.append("<resources>");
    float cellh = h * 1.0f / baseH;
    System.out.println("height : " + h + "," + baseH + "," + cellh);
    for (int i = 1; i < baseH; i++) {
        sbForHeight.append(HTemplate.replace("{0}", i + "").replace("{1}",
                change(cellh * i) + ""));
    }
    sbForHeight.append(HTemplate.replace("{0}", baseH + "").replace("{1}",
            h + ""));
    sbForHeight.append("</resources>");

    File fileDir = new File(dirStr + File.separator
            + VALUE_TEMPLATE.replace("{0}", h + "")//
                    .replace("{1}", w + ""));
    fileDir.mkdir();

    File layxFile = new File(fileDir.getAbsolutePath(), "lay_x.xml");
    File layyFile = new File(fileDir.getAbsolutePath(), "lay_y.xml");
    try {
        PrintWriter pw = new PrintWriter(new FileOutputStream(layxFile));
        pw.print(sbForWidth.toString());
        pw.close();
        pw = new PrintWriter(new FileOutputStream(layyFile));
        pw.print(sbForHeight.toString());
        pw.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

public static float change(float a) {
    int temp = (int) (a * 100);
    return temp / 100f;
}

public static void main(String[] args) {
    int baseW = 320;
    int baseH = 400;
    String addition = "";
    try {
        if (args.length >= 3) {
            baseW = Integer.parseInt(args[0]);
            baseH = Integer.parseInt(args[1]);
            addition = args[2];
        } else if (args.length >= 2) {
            baseW = Integer.parseInt(args[0]);
            baseH = Integer.parseInt(args[1]);
        } else if (args.length >= 1) {
            addition = args[0];
        }
    } catch (NumberFormatException e) {

        System.err
                .println("right input params : java -jar xxx.jar width height w,h_w,h_..._w,h;");
        e.printStackTrace();
        System.exit(-1);
    }

    new GenerateValueFiles(baseW, baseH, addition).generate();
}
點擊查看更多內(nèi)容
15人點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
移動開發(fā)工程師
手記
粉絲
4
獲贊與收藏
155

關(guān)注作者,訂閱最新文章

閱讀免費教程

感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優(yōu)惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消