import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.widget.TextView;

public class test extends Activity {
    
	TextView ans = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        ans = (TextView) findViewById( R.id.ans );
        //建立一個DisplayMetrics物件
        DisplayMetrics dm = new DisplayMetrics();
        //取得裝置的資訊
        this.getWindowManager().getDefaultDisplay().getMetrics(dm);
        
        //寬
        int vWidth = dm.widthPixels;
        //高
        int vHeight = dm.heightPixels;
        ans.setText("寬:" + vWidth + " 長:" + vHeight );
    }
}
Categories: Android