簡體   English   中英

如何區分兩個不同的android mdpi手機

[英]how to distinguish two different android mdpi phones

我試圖編寫應用程序的女巫在所有(或大多數)Android手機上看起來都類似。 我有兩部手機有問題:Samsung Galaxy Ace 2和Samsung Galaxy mini2。整個布局在galaxy ace中占據整個屏幕,對於mini來說太大了。

首先,我嘗試為ldpi和mdpi指定不同的調暗度,但是似乎兩部手機都使用了mdpi值。 然后,我也嘗試通過屏幕大小來區分它們,並將文件夾值設置為normal-mdpi。 我認為ace應該是“大”的,它具有480x800的分辨率,並且根據文檔的要求應該大: 支持多屏 但是,兩個電話都從“ 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>

最后一個按鈕在較小的手機上不可見。 如果我希望兩者看起來相同,我應該怎么做?

好吧,事實證明兩者都不是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)。

我認為使用尺寸是一種很好的做法,但是您必須正確選擇分類器。 您必須知道ldpi,mdpi,hdpi,xhdpi和xxhdpi代表設備屏幕中像素的密度。 在這種情況下,您可能想嘗試“最小寬度”分類器。 例如,如果您有2個屏幕,均為mdpi,但其中一個屏幕的寬度為240度,而另一個屏幕為320度,則應將尺寸放置在“ values-sw240dp”和“ values-sw320dp”文件夾下。

希望能幫助到你。

除特殊情況外,您實際上不需要為不同的屏幕尺寸使用不同的尺寸。 而是使用layout.xml中的屬性來定義布局中元素的縮放比例。 例如,無論屏幕大小如何,android:layout_width =“ match_parent”始終將元素的寬度與父元素的寬度匹配。 查看有關xml布局的此鏈接以開始使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM