简体   繁体   English

如何区分两个不同的android mdpi手机

[英]how to distinguish two different android mdpi phones

Im trying to write app witch will look similar on all (or most) android phones. 我试图编写应用程序的女巫在所有(或大多数)Android手机上看起来都类似。 I have a problem with two phones: Samsung Galaxy Ace 2 and Samsung Galaxy mini 2. Layout that takes whole screen in galaxy ace is too large for galaxy mini. 我有两部手机有问题:Samsung Galaxy Ace 2和Samsung Galaxy mini2。整个布局在galaxy ace中占据整个屏幕,对于mini来说太大了。

First I tried to specify different dimens for ldpi and mdpi, but it appeared that both phones used mdpi values. 首先,我尝试为ldpi和mdpi指定不同的调暗度,但是似乎两部手机都使用了mdpi值。 Then I was trying too distinguish them by screen sizes and made folder values-normal-mdpi. 然后,我也尝试通过屏幕大小来区分它们,并将文件夹值设置为normal-mdpi。 I thought that ace should be "large", it has 480x800 resolution and should be large accordinng to documentation: Supporting Multiple Screens . 我认为ace应该是“大”的,它具有480x800的分辨率,并且根据文档的要求应该大: 支持多屏 However both phones take values from the "normal-mdpi" folder. 但是,两个电话都从“ normal-mdpi”文件夹中获取值。 On the other hand I have seen application that look identical on both phones, how can I do this? 另一方面,我在两部手机上看到的应用程序看起来完全相同,该怎么办?

Edit: 编辑:

imagine I have a very simple layout only with simple views: 假设我只有一个简单的视图,就拥有一个非常简单的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

<Button
    android:id="@+id/button4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

<Button
    android:id="@+id/button5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

<TextView
    android:id="@+id/textView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
    android:id="@+id/button6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" /></LinearLayout>

The last button is not visible on smaller phone. 最后一个按钮在较小的手机上不可见。 What shoud I do if I want this to look identical on both? 如果我希望两者看起来相同,我应该怎么做?

Well, it turns out that none of the two is an mdpi device: 好吧,事实证明两者都不是mdpi设备:
Samsung Galaxy Ace 2: WVGA (480x800) resolution (about 244 dpi) = hdpi 三星Galaxy Ace 2:WVGA(480x800)分辨率(约244 dpi)= hdpi
Samsung Galaxy Mini 2: QVGA (240×320) resolution (about 127 dpi) = ldpi 三星Galaxy Mini 2:QVGA(240×320)分辨率(约127 dpi)= ldpi

So, the drawable folders for your graphics should be: 因此,图形的可绘制文件夹应为:
res/drawable-ldpi RES /抽拉-LDPI
res/drawable-hdpi RES /抽拉-HDPI

Please note that you should provide pngs at the proper resolutions (120 and 240 dpi). 请注意,您应该以适当的分辨率(120和240 dpi)提供png。
You can choose to provide a normal resolution graphics (160 dpi, which is mdpi ) and it will be scaled to 120 dpi (0.75x) for ldpi devices and to 240dpi (2.0x) for hdpi devices 您可以选择提供普通分辨率的图形(160 dpi,即mdpi ),对于ldpi设备,它将缩放到120 dpi(0.75x);对于hdpi设备,它将缩放到240dpi(2.0x)。

I think is a very good practice the use of dimensions but you must choose your classifiers properly. 我认为使用尺寸是一种很好的做法,但是您必须正确选择分类器。 You must know that ldpi, mdpi, hdpi, xhdpi and xxhdpi stand for the density of pixels in the screen of devices. 您必须知道ldpi,mdpi,hdpi,xhdpi和xxhdpi代表设备屏幕中像素的密度。 In this case you're exposing, you may wanna try the "smallest width" classifier. 在这种情况下,您可能想尝试“最小宽度”分类器。 For example, if you have 2 screens, both mdpi, but one of them is 240 dips width and the other is 320 dips, you should place dimensions under the folders "values-sw240dp" and "values-sw320dp". 例如,如果您有2个屏幕,均为mdpi,但其中一个屏幕的宽度为240度,而另一个屏幕为320度,则应将尺寸放置在“ values-sw240dp”和“ values-sw320dp”文件夹下。

Hope it helps. 希望能帮助到你。

You shouldn't really need to use different dimensions for different screen sizes, except in special cases. 除特殊情况外,您实际上不需要为不同的屏幕尺寸使用不同的尺寸。 Instead, use the attributes in your layout.xml to define how the elements in your layout should scale. 而是使用layout.xml中的属性来定义布局中元素的缩放比例。 For instance, android:layout_width = "match_parent" will always match that element's width to the width of the parent, no matter what the screen size. 例如,无论屏幕大小如何,android:layout_width =“ match_parent”始终将元素的宽度与父元素的宽度匹配。 Check out this link about xml layouts to get started. 查看有关xml布局的此链接以开始使用。

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

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