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

时间:2013-12-11 21:34:37

标签: android size screen android-screen-support mdpi

我试图编写应用程序女巫将在所有(或大多数)Android手机上看起来类似。我有两个手机的问题:三星Galaxy Ace 2和三星Galaxy mini 2.在Galaxy ace中采用整个屏幕的布局对于galaxy mini来说太大了。

首先,我尝试为ldpi和mdpi指定不同的尺寸,但似乎两部手机都使用了mdpi值。然后我试图通过屏幕大小区分它们并使文件夹值 - normal-mdpi。我认为ace应该是“大”的,它具有480x800的分辨率,并且应该根据文档大Supporting Multiple Screens。 但是,两部手机都从“normal-mdpi”文件夹中获取值。另一方面,我看到在两部手机上看起来相同的应用程序,我该怎么做?

编辑:

想象一下,我只有一个非常简单的布局,只有简单的视图:

<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>

小手机上看不到最后一个按钮。如果我希望两者看起来相同,我该怎么办?

3 个答案:

答案 0 :(得分:1)

嗯,事实证明这两者都不是mdpi设备:
三星Galaxy Ace 2:WVGA(480x800)分辨率(约244 dpi)= hdpi
三星Galaxy Mini 2:QVGA(240×320)分辨率(约127 dpi)= ldpi

因此,图形的可绘制文件夹应为:
RES /抽拉-LDPI
RES /抽拉-HDPI

请注意,您以正确的分辨率(120和240 dpi)提供png。
您可以选择提供普通分辨率图形(160 dpi,其中 mdpi )对于ldpi设备它将被缩放到120 dpi(0.75x),对于hdpi设备将被缩放到240dpi(2.0x)

答案 1 :(得分:1)

我认为使用尺寸是一种非常好的做法,但您必须正确选择分类器。您必须知道ldpi,mdpi,hdpi,xhdpi和xxhdpi代表设备屏幕中的像素密度。 在这种情况下你暴露,你可能想尝试“最小宽度”分类器。例如,如果您有两个屏幕,两个mdpi,但其中一个是240 dips宽度,另一个是320 dips,则应将尺寸放在文件夹“values-sw240dp”和“values-sw320dp”下。

希望它有所帮助。

答案 2 :(得分:0)

除特殊情况外,您不应该为不同的屏幕尺寸使用不同的尺寸。而是使用layout.xml中的属性来定义布局中元素的缩放方式。例如,android:layout_width =“match_parent”将始终将该元素的宽度与父级的宽度匹配,无论屏幕大小如何。查看有关xml布局的link以开始使用。