2013-12-11 28 views
1

我试图写应用程序女巫将看起来类似的所有(或大多数)Android手机。我有两个手机的问题:三星Galaxy Ace 2和三星Galaxy mini 2.银河王牌需要整个屏幕的布局对于银河迷你来说太大了。如何区分两个不同的android mdpi电话

首先,我试图为ldpi和mdpi指定不同的维度,但似乎两个手机都使用了mdpi值。然后我试图通过屏幕大小来区分它们,并将文件夹值设置为normal-mdpi。我认为王牌应该是“大”,它具有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> 

最后一个按钮是不是在较小的手机可见。如果我想让这两个看起来完全相同,我该怎么办?

+0

你的xml看起来像什么 – tyczj

+0

你应该把所有的东西都包含在scrollview中,那么无论多大的屏幕是 – tyczj

回答

1

好了,事实证明,没有任何两个是MDPI装置:
三星Galaxy王牌2:WVGA(480×800)分辨率(大约244 DPI)= HDPI
三星Galaxy赠送2:QVGA(240 ×320)分辨率(约127 DPI)= LDPI

所以,对于图形的绘制文件夹应该是:
RES /提拉 - LDPI
RES /提拉 - 华电国际

请注意,您应该以正确的分辨率(120和240 dpi)提供PNG。
可以选择,以提供正常分辨率的图形(160 dpi的,这是MDPI),它会被缩放至120 DPI(0.75倍),用于LDPI设备和到240dpi(2.0倍),用于HDPI设备

+0

哇,你对王牌手机是正确的。这就是为什么它没有按照我的预期行事。迷你实际上是真正的mdpi(它的迷你2,你的参数是迷你型),但那并不真正。这解决了我的问题,非常感谢:) – user3092760

+0

我很高兴至少让你在正确的方向。 ;)我发现维基百科上的规格... –

0

除特殊情况外,您不需要针对不同的屏幕尺寸真的需要使用不同的尺寸。相反,使用layout.xml中的属性来定义布局中的元素应如何缩放。例如,无论屏幕大小如何,android:layout_width =“match_parent”都将始终将该元素的宽度与父级宽度相匹配。看看这个link关于xml布局开始。

+0

谢谢你的快速回答。我把android:layout_height =“match_parent”放在线性布局上,但是里面的元素没有缩放。我可以以某种方式强制它,所以它在每个mdpi手机上看起来都一样吗? – user3092760

1

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

希望它有帮助。

+0

看来我的问题是关于我不知道我的手机密度。无论如何感谢您的答案。 – user3092760

相关问题