WEB开发网
开发学院手机开发Android 开发 Android 获取屏幕分辨率的例子 阅读

Android 获取屏幕分辨率的例子

 2010-09-10 00:45:00 来源:WEB开发网   
核心提示:程序代码如下:package com.acquire.resolution;import android.app.Activity;import android.content.res.Resources;import android.graphics.Color;import android.graphics.dra

程序代码如下:

package com.acquire.resolution;

import android.app.Activity;

import android.content.res.Resources;

import android.graphics.Color;

import android.graphics.drawable.Drawable;

import android.os.Bundle;

import android.util.DisplayMetrics;

import android.widget.TextView;

public class AcquireResolution extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

TextView tv = (TextView)findViewById(R.id.textView);

Resources resources = getBaseContext().getResources();

Drawable drawable = resources.getDrawable(R.drawable.red);

tv.setBackgroundDrawable(drawable);

tv.setTextColor(Color.GREEN);

DisplayMetrics dm = new DisplayMetrics();

getWindowManager().getDefaultDisplay().getMetrics(dm);

tv.setText("屏幕分辨率为:"+dm.widthPixels+" * "+dm.heightPixels);

}

}

package com.acquire.resolution;

import android.app.Activity;

import android.content.res.Resources;

import android.graphics.Color;

import android.graphics.drawable.Drawable;

import android.os.Bundle;

import android.util.DisplayMetrics;

import android.widget.TextView;

public class AcquireResolution extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

TextView tv = (TextView)findViewById(R.id.textView);

Resources resources = getBaseContext().getResources();

1 2  下一页

Tags:Android 获取 屏幕

编辑录入:coldstar [复制链接] [打 印]
赞助商链接