-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 に答える