联系
我们
投稿
反馈
评论 返回
顶部

内容字号: 默认 大号超大号

段落设置: 段首缩进取消段首缩进

字体设置:切换到微软雅黑切换到宋体

Android学习笔记之获取手机屏幕大小

2017-07-14 12:02 出处:互联网 人气: 评论(
战王龙妃 总裁老公乖乖听话 大广高速路况实时查询 素女经秘戏图本 一起长大慢慢变老 天龙猎艳之邪帝虚竹 绥芬河信息网 听说你要娶老子 食木甲鲶鱼

下面是获取屏幕分辨率的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  super.setContentView(R.layout.activity_main);
 }

float xdpi
The absolute width of the display in pixels.

public class MainActivity extends Activity

static int DEFAULT_DENSITY
  this.text=(TextView)super.findViewById(R.id.text);
 protected void onCreate(Bundle savedInstanceState)
The logical density of the display.

float scaledDensity
        android:id="@+id/text"

android可设置为随着窗口大小调整缩放比例,但即便如此,手机程序设计人员还是必须清楚地知道手机屏幕的边界,以免缩放之后造成的布局(Layout)变形问题。在android中,只需几行代码就可以取得手机屏幕分辨率,其中的关键则是DisplayMetrics类的应用。

int heightPixels

Android手机的屏幕尺寸问题一直是让开发者感觉很头疼的问题,由于各手机厂商所采用的屏幕尺寸不同,user UI接口呈现及布局自然也各自迥异。所以,在开发android手机应用程序时,除了对底层API的掌握之外,最重要的仍是屏幕分辨率概念的理解。

float density
 @Override

</RelativeLayout>

    android:layout_height="match_parent"

程序运行效果截图:

布局文件非常简单,一个TextView组件即可:

    android:layout_width="match_parent"
        android:layout_height="wrap_content" />

Android学习笔记之获取手机屏幕大小

The absolute height of the display in pixels.

    android:paddingTop="@dimen/activity_vertical_margin"
 {
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

  super.getWindowManager().getDefaultDisplay().getMetrics(dm);
    android:paddingLeft="@dimen/activity_horizontal_margin"
  String strOpt="手机屏幕分辨率为:"+dm.widthPixels+"*"+dm.heightPixels;
  super.onCreate(savedInstanceState);
The reference density used throughout the system.

{

DisplayMetrics类直接继承自Object类,存放在Android.util包下。DisplayMetrics对象记录了一些常用的信息,包含了显示信息、大小、维度和字体等,如下表所示:

int widthPixels
  DisplayMetrics dm=new DisplayMetrics();

float ydpi
    xmlns:tools="http://schemas.android.com/tools"
The exact physical pixels per inch of the screen in the Y dimension.

    private TextView text=null;

值得一提的是,widthPixels和heightPixels记录了手机屏幕的宽和高,我们使用这两个值便可得到手机屏幕分辨率。注意此处的像素指的是绝对(Absolute)像素,而非相对像素。

    android:paddingRight="@dimen/activity_horizontal_margin"
A scaling factor for fonts displayed on the display.

    <TextView

linux

The exact physical pixels per inch of the screen in the X dimension.

  this.text.setText(strOpt);
        android:layout_width="wrap_content"

}

分享给小伙伴们:
本文标签:

更多文章

相关文章

  • 蛮便宜
  • 抠门网
  • Copyright © 2002-2014 版权所有