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

标签 android size screen android-screen-support mdpi

我正在尝试编写在所有(或大多数)Android 手机上看起来都相似的应用程序。我有两部手机有问题:Samsung Galaxy Ace 2 和 Samsung Galaxy mini 2。galaxy ace 中占据整个屏幕的布局对于 galaxy mini 来说太大了。

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

编辑:

假设我有一个非常简单的布局,只有简单的 View :

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

最后一个按钮在较小的手机上不可见。如果我想让两者看起来相同,我应该怎么做?

最佳答案

嗯,结果发现这两个都不是mdpi设备:
Samsung Galaxy Ace 2:WVGA (480x800) 分辨率(约 244 dpi)= hdpi
三星 Galaxy Mini 2:QVGA (240×320) 分辨率(约 127 dpi)= ldpi

因此,您的图形的可绘制文件夹应该是:
res/drawable-ldpi
res/drawable-hdpi

请注意,您应该以适当的分辨率(120 和 240 dpi)提供 png。
您可以选择提供正常分辨率的图形(160 dpi,这是 mdpi),对于 ldpi 设备它将缩放到 120 dpi (0.75x),对于 hdpi 设备将缩放到 240dpi (2.0x)

关于android - 如何区分两个不同的android mdpi手机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20530367/

相关文章:

c# - 如何使用 Xamarin 在 Android 中同步获取 GPS 位置更新?

android - 如何正确设置数组的大小?

html - @media 打印 XS 和 SM 屏幕尺寸的问题

android - 在整个屏幕上移动 TextView

c++ - 使用巨大 vector 卡住 C++ 程序

Java 屏幕空白

Android 截击超时无法正常工作

java - 在android的服务中调用位置管理器两次

java - 禁用在一个滑动选项卡中滑动

c++ - 如何确定 C++ 中对象的大小?