首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >hdpi/ldpi/mdpi图形尺寸

hdpi/ldpi/mdpi图形尺寸
EN

Stack Overflow用户
提问于 2011-11-23 03:05:05
回答 4查看 23K关注 0票数 23

我有一个尺寸为300*90的按钮图形。hdpi/mdpi/ldpi的尺寸必须是多少?谢谢

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-11-23 03:12:26

谷歌suggests使用

3 : 4 : 6 : 8 : 12 : 16缩放比率

相应的ldpi : mdpi : hdpi : xhdpi : xxhdpi : xxxhdpi。示例:

适用于适用于high-density

  • 96x96的low-density

  • 48x48的

  • 36x36,适用于适用于extra-extra-extra-high-density

的extra-extra-high-density

  • 192x192的额外high-density

  • 144x144

在您的示例中,如果提到的按钮大小用于hdpi,则正确的尺寸应为:

  • 150x45 ldpi
  • 200x60 mdpi
  • 300x90 hdpi
  • 400x120 xxxhdpi

<代码>F230

票数 61
EN

Stack Overflow用户

发布于 2011-11-23 03:11:32

这取决于您设计该图形所依据的设备屏幕的大小。如果您希望它在320x480 (HVGA)画布上显示为300x90,则您的像素尺寸对于MDPI设备是正确的,并且您需要以下图像:

  • LDPI: 225x68px
  • MDPI: 300x90px
  • HDPI: 450x135px

LDPI是MDPI缩放的75%,HDPI是MDPI缩放的150%。例如,如果您在480x800 (WVGA)画布上设计了这些图形尺寸,那么您的尺寸对于HDPI来说已经是正确的,并且您需要从那里缩小其他两个尺寸:

150x45px

  • MDPI: 200x60px

  • HDPI:
  • LDPI: 300x90px

希望这能有所帮助!

票数 5
EN

Stack Overflow用户

发布于 2014-02-22 11:38:16

用于创建所有资源文件夹映像的

完整公式

首先,您必须决定为哪个DPI创建图像,一旦您决定并创建了图像,然后根据Google Guide Lines使用以下代码

代码语言:javascript
复制
public class DPICalculator {

    private final float LDPI = 120;
    private final float MDPI = 160;
    private final float HDPI = 240;
    private final float XHDPI = 320;

    private final float BASE_DPI = MDPI;

    public static void main(String[] args) {
        DPICalculator cal = new DPICalculator();

        cal.calculateDPI_baseUnitPixel(300, 90, cal.HDPI);
    }

    private float densityWidth;
    private float densityHeight;

    public void calculateDPI_baseUnitPixel(float width, float height, float currentDensity) {

        densityWidth = getDensityPX(width, currentDensity);
        densityHeight = getDensityPX(height, currentDensity);

        this.calculateAllDP();
    }

    private float getDensityPX(float value, float currentDensity) {
        return (value / (currentDensity / BASE_DPI));
    }

    public void calculateDPI_baseUnitDPI(float width, float height, float currentDensity) {

        densityWidth = getDensityDPI(width, currentDensity);
        densityHeight = getDensityDPI(height, currentDensity);

        this.calculateAllDP();
    }

    private float getDensityDPI(float value, float currentDensity) {
        return (value * (currentDensity / BASE_DPI));
    }

    private void calculateAllDP() {
        // get all settings.
        float low_pw = densityWidth * (LDPI / BASE_DPI);
        float low_ph = densityHeight * (LDPI / BASE_DPI);

        float med_pw = densityWidth * (MDPI / BASE_DPI);
        float med_ph = densityHeight * (MDPI / BASE_DPI);

        float high_pw = densityWidth * (HDPI / BASE_DPI);
        float high_ph = densityHeight * (HDPI / BASE_DPI);

        float xhigh_pw = densityWidth * (XHDPI / BASE_DPI);
        float xhigh_ph = densityHeight * (XHDPI / BASE_DPI);

        System.out.println("LDPI " + low_pw + " x " + low_ph);
        System.out.println("MDPI " + med_pw + " x " + med_ph);
        System.out.println("HDPI " + high_pw + " x " + high_ph);
        System.out.println("XHDPI " + xhigh_pw + " x " + xhigh_ph);

    }
}

结果

代码语言:javascript
复制
LDPI 150.0 x 45.0
MDPI 200.0 x 60.0
HDPI 300.0 x 90.0
XHDPI 400.0 x 120.0
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8232322

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档