你的位置:首页 > 操作系统

[操作系统]android 获得屏幕宽度和高度

<RelativeLayout ="http://schemas.android.com/apk/res/android"  ="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical" >  <!-- 显示网络状态的标签控件 -->  <TextView    android:id="@+id/myyl"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:textSize="20dp" /></RelativeLayout>

 

package com.example.yanlei.yl;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.content.Context;import android.graphics.Canvas;import android.graphics.Paint;import android.view.Gravity;import android.view.View;import android.view.WindowManager;import android.widget.TextView;public class MainActivity extends AppCompatActivity {  private TextView pTextView;  @Override  public void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    WindowManager wm = this.getWindowManager();    int width = wm.getDefaultDisplay().getWidth();    int height = wm.getDefaultDisplay().getHeight();    pTextView=(TextView)findViewById(R.id.myyl);    pTextView.setText("屏幕宽度:"+width+",屏幕高度:"+height);  }}