Android的过氧化物转换为DP(视频宽高比)过氧化物、转换为、视频、Android

由网友(over -私恋 °)分享简介:可能重复: 转换像素的安卓 DP 我想要的像素转换为DP。公式是什么?让转换640和480到DP。该文档说这种的DP单位,以屏幕像素转换非常简单:PX = DP *(DPI / 160)但我不认为这是我所需要的(我不知道怎么用这个)。我想我只需要forumla。我有code准备:DisplayMetrics指标=新D...

可能重复:   转换像素的安卓 DP

我想要的像素转换为DP。公式是什么?

让转换640和480到DP。该文档说这种

  

的DP单位,以屏幕像素转换非常简单:PX = DP *(DPI / 160)

但我不认为这是我所需要的(我不知道怎么用这个)。我想我只需要forumla。我有code准备:

  DisplayMetrics指标=新DisplayMetrics();
    。getWindowManager()getDefaultDisplay()getMetrics(度量)。

    开关(metrics.densityDpi)
    {
         案例DisplayMetrics.DENSITY_LOW:
         INT sixForty =?
         INT fourEighty =?
         打破;

         案例DisplayMetrics.DENSITY_MEDIUM:
         INT sixForty =?
         INT fourEighty =?
         打破;

         案例DisplayMetrics.DENSITY_HIGH:
         INT sixForty =?
         INT fourEighty =?
         打破;
    }
 

解决方案

而不是试图推断从屏幕上的密度分级DP转换系数,也可以直接查询它:

  getWindowManager()getDefaultDisplay()getMetrics(指标)。;
浮logicalDensity = metrics.density;
 

logicalDensity则包含你需要乘DP通过获取物理像素尺寸的设备屏幕的因素。

  INT PX =(int)的Math.ceil(DP * logicalDensity);
 
cucusoft DVD to iPod Converter和闪电Android视频转换器对比 ZOL下载

Possible Duplicate: converting pixels to dp in android

I'm trying to convert pixels to dp. What is the formula?

Lets convert 640 and 480 into dp. The docs say this

The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160)

But I don't think that is what I need (and I don't know how to use this). I guess I just need the forumla. I have the code ready:

DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);

    switch(metrics.densityDpi)
    {
         case DisplayMetrics.DENSITY_LOW:
         int sixForty = ?
         int fourEighty = ?
         break;

         case DisplayMetrics.DENSITY_MEDIUM:
         int sixForty = ?
         int fourEighty = ?
         break;

         case DisplayMetrics.DENSITY_HIGH:
         int sixForty = ?
         int fourEighty = ?
         break;
    }

解决方案

Instead of trying to infer the dp conversion factor from the screen's density classification, you can simply query it directly:

getWindowManager().getDefaultDisplay().getMetrics(metrics);
float logicalDensity = metrics.density;

logicalDensity will then contain the factor you need to multiply dp by to get physical pixel dimensions for the device screen.

int px = (int) Math.ceil(dp * logicalDensity);

阅读全文

相关推荐

最新文章