package com.moonlight_aska.android.displaysize;
import android.app.Activity;
import android.os.Bundle;
import android.view.Display;
import android.view.WindowManager;
import android.widget.TextView;
public class DisplaySize extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView txWidth = (TextView)findViewById(R.id.width_id);
TextView txHeight = (TextView)findViewById(R.id.height_id);
// WindowManagerのインスタンス取得
WindowManager wm = getWindowManager();
// Displayのインスタンス取得
Display disp = wm.getDefaultDisplay();
String width = "Width = " + disp.getWidth();
String height = "Height = " + disp.getHeight();
txWidth.setText(width);
txHeight.setText(height);
}
}
WindowManager wm = (WindowManager)getSystemService(WINDOW_SERVICE);
// ディスプレイのインスタンス生成
Display disp = wm.getDefaultDisplay();
Point size = new Point();
disp.getSize(size);
String width = "Width = " + size.x;
String height = "Height = " + size.y;
WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE);
Display disp = wm.getDefaultDisplay();
int width = disp.getWidth();
int height = disp.getHeight();