-1

我的问题是我想通过每行显示 2 张图像来重新调整帖子中所有图像的大小

我的应用程序将屏幕宽度发送到 php api php api 必须将倾角转换为像素并将图像宽度设置为屏幕倾角的 50%

这是迄今为止的目标

Display d = getWindowManager().getDefaultDisplay(); 

int w = display.getWidth();  
int h = display.getHeight(); 

String response = get_html_postinfo("bla.php?postid=1&h="+h+"&w="+w);

//response will append it to WebView

在php端

$screen_dip_w = $_GET['w'];
$screen_dip_h = $_GET['h'];

//i want this dip to be converted to pixel how ?
$screen_px_w = ( ? X $screen_dip_w );

$set_image_w = $screen_px_w/2;

任何想法 ?感谢你

4

2 回答 2

3

Display.getWidth()并且Display.getHeight()已经以像素为单位返回屏幕大小,不需要转换。

另外,我建议切换到使用Display.getSize(Point outSize),因为不推荐使用宽度和高度方法。

developer.android.com/reference/android/view/Display.html

于 2014-01-31T18:10:05.727 回答
1

这是我找到的一些解决方案:

public static int dpToPx(int dp)
{
    return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
}

public static int pxToDp(int px)
{
    return (int) (px / Resources.getSystem().getDisplayMetrics().density);
}

和这个:

// Converts 14 dip into its equivalent px

Resources r = getResources();
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, r.getDisplayMetrics());
于 2014-01-31T18:38:01.427 回答