Andropoda fit exploration

Android adaptation has always been a big hate of Android developers. Fortunately, Android 5.0 provides a universal adaptation method. For details, please refer to Zhang Hongyang's universal adapter. However, it doesn't necessarily work for the development of TV or the Internet of things in the current fire, because the companion machine of the Internet of things development partners is still 4 +, so it still uses multiple values, Of course, I will never let you write one by one. Brother lazybones has prepared dry goods for you. (play through, the next article is silent upgrade startup and barrier free operation exploration).
The lazy share chapter three: the exploration of andropoda fit

Use help:
1.Create other values Resource files and dimin
2.Enable core code(Right click to java Remember to add file read-write permission),How many times are generated? Set by yourself
//Popularization of basic knowledge
//The minimum width shall prevail, if the actual screen is480*800 ,Yes values-sw900dp and values-sw720dp,values-sw420dp So what we actually use is values-sw420dp Of dimin
2.sw and w
//In resources:value-w1280dp,value-w800dp,Use under horizontal screenvalue-w1280dp Resources, vertical screen usevalue-w800dp Resources for.
//In resources:value-sw800dp,value-sw1080dp Use under horizontal screenvalue-sw800dp Resources, still in use under the vertical screenvalue-sw800dp Resources for.
//If the resources in the fourth middle school of appeal exist at the same time, sw resources are preferred,value-sw800dp

  //Core code
  //There is a problem with code layout. If you copy and format it yourself, you will not add QQ1377792567, indicating the source
  public class DimenTool {

    public static void gen() {

        File file = new File("./app/src/main/res/values/dimens.xml");
        BufferedReader reader = null;
        StringBuilder sw900 = new StringBuilder();
        StringBuilder sw1024 = new StringBuilder();

        try {
            System.out.println("Generate different resolutions:");
            reader = new BufferedReader(new FileReader(file));
            String tempString;
            int line = 1;
            //  Read in one line at a time until null is the end of the file

            while ((tempString = reader.readLine()) != null) {

                if (tempString.contains("</dimen>")) {
                    //tempString  =  tempString.replaceAll("  ",  "");
                    String start = tempString.substring(0, tempString.indexOf(">") + 1);
                    String end = tempString.substring(tempString.lastIndexOf("<") - 2);
                    int num = Integer.valueOf(tempString.substring(tempString.indexOf(">") + 1, tempString.indexOf("</dimen>") - 2));

                    sw900.append(start).append((int) Math.round(num * 1.2)).append(end).append("\n");
                    sw1024.append(start).append((int) Math.round(num * 1.5)).append(end).append("\n");

                } else {

            String sw900file = "./app/src/main/res/values-sw900dp/dimens.xml";
            String sw1024file = "./app/src/main/res/values-sw1024dp/dimens.xml";
            writeFile(sw900file, sw900.toString());
            writeFile(sw1024file, sw1024.toString());
        } catch (IOException e) {
        } finally {
            if (reader != null) {
                try {
                } catch (IOException e1) {

    public static void writeFile(String file, String text) {
        PrintWriter out = null;
        try {
            out = new PrintWriter(new BufferedWriter(new FileWriter(file)));
        } catch (IOException e) {


    public static void main(String[] args) {

Tags: Android xml Java

Posted on Sun, 31 May 2020 07:37:53 -0700 by jamz310