example.java import android.app.Activity; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.Window; import android.view.WindowManager; import android.widget.TextView; public class example0305 extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); //全螢幕設定 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); TextView TextView1 = (TextView)findViewById(R.id.TextView01); TextView1.setText("手機銀幕大小為 "+metrics.widthPixels+" X "+metrics.heightPixels); } } main.xml xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/TextView01" android:textSize="20sp" /> </LinearLayout>
程式主要的重點在於
import android.util.DisplayMetrics;
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
沒有留言:
張貼留言