Galaxy Tab2属于HDPI或MDPI解析桶

时间:2013-03-20 04:38:02

标签: android android-layout

我开发了Galaxy Tab2的应用程序。它的屏幕分辨率为600 * 1024(169 PPI)。根据{{​​3}},它属于HDPI Android解析桶。然后该设备的最小宽度为600 PPI。然后除以1.50给出400 dp。所以它的最小宽度是400 dp。然后它转到sw-320dp文件夹。但实际上它应该在sw600dp中。

所以我的疑问是Tab2 id HDPI或MDPI?或者我在计算中犯了什么错误?

我的代码:

public void calculate(View view)
    {
        EditText widthResolution=(EditText)findViewById(R.id.dip_et_screenwidthres);
        EditText heightResolution=(EditText)findViewById(R.id.dip_et_screenheightres);
        EditText size=(EditText)findViewById(R.id.dip_et_screensize);


        String screenWidth = widthResolution.getText().toString();
        Double screenWidthD=Double.valueOf(screenWidth);

        String screenHeight = heightResolution.getText().toString();
        Double screenHeightD=Double.valueOf(screenHeight);

        String screenSize = size.getText().toString();
        Double screenSizeD=Double.valueOf(screenSize);

        Double sumOfXY2=(screenWidthD*screenWidthD)+(screenHeightD*screenHeightD);
        double totalDiagonalRes = Math.sqrt(sumOfXY2);

        Double diagonalPPI =totalDiagonalRes/screenSizeD;

        //used for calculation
        int diagonalPPIInt=diagonalPPI.intValue();

        //Diagonal Resolution in PPI
        String resultDiagonalResolution=String.format("%.2f", diagonalPPI);

        //Android Resolution Bucket
        String resultAndroidResBucket="";
        String resultDiagonalDPSize="";
        String resultWidthHeightDP="";
        String resultSmallestWidthDP="";
        String resultLayoutFolder="";
        String resultDrawableFolder="";

        double smallestWidthDPTemp = 0;

        if(diagonalPPIInt<120)
        {
            resultAndroidResBucket="LDPI"; //0.75

            //Diagonal size
            double diagonalDPSize=diagonalPPI/0.75;
            resultDiagonalDPSize=String.format("%.2f", diagonalDPSize);

            //Width * Height
            double screenWidthDP=screenWidthD/0.75;
            String screenWidthTemp=String.format("%.2f", screenWidthDP);

            double screenHeightDP=screenHeightD/0.75;
            String screenHeightTemp=String.format("%.2f", screenHeightDP);

            resultWidthHeightDP=screenWidthTemp+" dp * "+screenHeightTemp+" dp";

            //Smallest Width
            smallestWidthDPTemp=Math.min(screenWidthDP, screenHeightDP);
            resultSmallestWidthDP=String.format("%.2f", smallestWidthDPTemp);

            //DrawableFolder
            resultDrawableFolder="drawable-ldpi";
        }
        else if(diagonalPPIInt >= 120 && diagonalPPIInt < 160)
        {
            resultAndroidResBucket="MDPI"; //0.00

            //Diagonal size
            double diagonalDPSize=diagonalPPI;
            resultDiagonalDPSize=String.format("%.2f", diagonalDPSize);

            //Width * Height
            double screenWidthDP=screenWidthD;
            String screenWidthTemp=String.format("%.2f", screenWidthDP);

            double screenHeightDP=screenHeightD;
            String screenHeightTemp=String.format("%.2f", screenHeightDP);

            resultWidthHeightDP=screenWidthTemp+" dp * "+screenHeightTemp+" dp";

            //Smallest Width
            smallestWidthDPTemp=Math.min(screenWidthDP, screenHeightDP);
            resultSmallestWidthDP=String.format("%.2f", smallestWidthDPTemp);

            //DrawableFolder
            resultDrawableFolder="drawable-mdpi";
        }
        else if(diagonalPPIInt >= 160 && diagonalPPIInt < 240)
        {
            resultAndroidResBucket="HDPI"; //1.50

            //Diagonal size
            double diagonalDPSize=diagonalPPI/1.50;
            resultDiagonalDPSize=String.format("%.2f", diagonalDPSize);

            //Width * Height
            double screenWidthDP=screenWidthD/1.50;
            String screenWidthTemp=String.format("%.2f", screenWidthDP);

            double screenHeightDP=screenHeightD/1.50;
            String screenHeightTemp=String.format("%.2f", screenHeightDP);

            resultWidthHeightDP=screenWidthTemp+" dp * "+screenHeightTemp+" dp";

            //Smallest Width
            smallestWidthDPTemp=Math.min(screenWidthDP, screenHeightDP);
            resultSmallestWidthDP=String.format("%.2f", smallestWidthDPTemp);

            //DrawableFolder
            resultDrawableFolder="drawable-hdpi";
        }
        else if(diagonalPPIInt >= 240 && diagonalPPIInt < 320)
        {
            resultAndroidResBucket="XHDPI"; //2.00

            //Diagonal size
            double diagonalDPSize=diagonalPPI/2.00;
            resultDiagonalDPSize=String.format("%.2f", diagonalDPSize);

            //Width * Height
            double screenWidthDP=screenWidthD/2.00;
            String screenWidthTemp=String.format("%.2f", screenWidthDP);

            double screenHeightDP=screenHeightD/2.00;
            String screenHeightTemp=String.format("%.2f", screenHeightDP);

            resultWidthHeightDP=screenWidthTemp+" dp * "+screenHeightTemp+" dp";

            //Smallest Width
            smallestWidthDPTemp=Math.min(screenWidthDP, screenHeightDP);
            resultSmallestWidthDP=String.format("%.2f", smallestWidthDPTemp);

            //DrawableFolder
            resultDrawableFolder="drawable-xhdpi";
        }
        else if(diagonalPPIInt >= 320)
        {
            resultAndroidResBucket="XXHDPI";

            //Diagonal size
            double diagonalDPSize=diagonalPPI/2.50;
            resultDiagonalDPSize=String.format("%.2f", diagonalDPSize);

            //Width * Height
            double screenWidthDP=screenWidthD/2.50;
            String screenWidthTemp=String.format("%.2f", screenWidthDP);

            double screenHeightDP=screenHeightD/2.50;
            String screenHeightTemp=String.format("%.2f", screenHeightDP);

            resultWidthHeightDP=screenWidthTemp+" dp * "+screenHeightTemp+" dp";

            //Smallest Width
            smallestWidthDPTemp=Math.min(screenWidthDP, screenHeightDP);
            resultSmallestWidthDP=String.format("%.2f", smallestWidthDPTemp);

            //DrawableFolder
            resultDrawableFolder="drawable-xxhdpi";
        }


        if(smallestWidthDPTemp >= 320 && smallestWidthDPTemp < 480 )
        {
            //Mobile
            resultLayoutFolder="layout-sw320dp";

        }
        else if(smallestWidthDPTemp >= 480 && smallestWidthDPTemp < 600 )
        {
            //5" Mobile
            resultLayoutFolder="layout-sw480dp";
        }
        else if(smallestWidthDPTemp >= 600 && smallestWidthDPTemp < 720 )
        {
            //7" Tablet
            resultLayoutFolder="layout-sw600dp";
        }
        else if(smallestWidthDPTemp >= 720)
        {
            //10" Tablet
            resultLayoutFolder="layout-sw720dp";
        }


        TextView diagonalResTV=(TextView)findViewById(R.id.dip_result_stv_diagonalres);
        diagonalResTV.setText(resultDiagonalResolution+" PPI");

        TextView androidResTV=(TextView)findViewById(R.id.dip_result_stv_androidresbucket);
        androidResTV.setText(resultAndroidResBucket);

        //For Android Developer Units in DP

        TextView diagonalsizeTV=(TextView)findViewById(R.id.dip_result_stv_diagonalsize);
        diagonalsizeTV.setText(resultDiagonalDPSize+" dp");

        TextView widthHeightTV=(TextView)findViewById(R.id.dip_result_stv_widthheight);
        widthHeightTV.setText(resultWidthHeightDP);

        TextView smallestWidthTV=(TextView)findViewById(R.id.dip_result_stv_smallestwidth);
        smallestWidthTV.setText(resultSmallestWidthDP+" dp");

        TextView layoutFolderTV=(TextView)findViewById(R.id.dip_result_stv_layoutfolder);
        layoutFolderTV.setText(resultLayoutFolder);

        TextView drawableFolderTV=(TextView)findViewById(R.id.dip_result_stv_drawablefolder);
        drawableFolderTV.setText(resultDrawableFolder);

    }

0 个答案:

没有答案