简体   繁体   English

Android屏幕分辨率不同

[英]Android screen in different resolutions

I want to develop an app which will support different screen sizes. 我想开发一个支持不同屏幕尺寸的应用程序。

I've read the official guide a lot of times, but I can not understand this. 我已经阅读了很多次官方指南 ,但是我听不懂。 I created a brand new app with a main activity, then I put a black square on the screen with 100dp x 100dp dimensions, just like this: 我创建了一个具有主要活动的全新应用,然后在屏幕上以100dp x 100dp尺寸放置了一个黑色方块,如下所示:

res/layout/activity_main.xml: RES /布局/activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#000000"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
         />


</RelativeLayout>

When I run this application on my emulator - I get this screen: 当我在模拟器上运行此应用程序时,出现以下屏幕: 在此处输入图片说明

And when I run the application on my device (Galaxy tab 2), I get a screen like this: 当我在设备上运行该应用程序时(“ Galaxy”选项卡2),我得到的屏幕如下: 在此处输入图片说明

As you can see, the square running on device is smaller than running on the emulator. 如您所见,在设备上运行的正方形比在仿真器上运行的正方形小。

I am using DP in my XML width and height. 我在XML宽度和高度中使用DP。 Is the square supposed to be in the same proportion in all resolutions? 正方形在所有分辨率中都应该具有相同的比例吗? If not, what can I do to get this square in the same size in all resolutions? 如果不是,我该怎么做才能在所有分辨率下获得相同大小的正方形?

Yes, this can be confusing. 是的,这可能会造成混淆。 However, different devices have different amounts of 'DP's. 但是,不同的设备具有不同数量的“ DP”。 The purpose of this is so that larger screens can hold more content. 这样做的目的是使更大的屏幕可以容纳更多内容。 If you're using images, you can provide different sizes for different screen densities. 如果您使用的是图像,则可以为不同的屏幕密度提供不同的尺寸。

For more info, see this page: http://developer.android.com/guide/practices/screens_support.html 有关更多信息,请参见以下页面: http : //developer.android.com/guide/practices/screens_support.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM