2013-10-31 70 views
0

我是Android新手,我正在開發應用程序。我已經閱讀了developers.google.com,如果我想要的應用程序屏幕兼容,那麼我的圖標應該在ldpi,mdpi,hdpi,xhdpi和android本身會選擇是這樣嗎?如果不是那麼我必須做它使屏幕兼容,以及如何給動態填充?像現在我的代碼看起來像這樣Android中的屏幕兼容性問題

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/splash_page" 
> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:layout_alignParentBottom="true" 
    android:gravity="center_vertical"> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="600dp" 
     android:layout_gravity="center_horizontal" 
     android:background="@drawable/icon_login_btn"/> 


    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:paddingTop="40dp" 
     android:background="@drawable/icon_btn_register" /> 

</LinearLayout> 

</RelativeLayout> 

所以,你在這裏看到我有給利潤率最高,但僅限於沒有在大屏幕手機平板電腦的工作。

回答

1
see if u want to go with layout format that you have to make some drawable like 
1.drawable-hdpi 
2.drawable-large 
3.drawable-ldpi 
4.drawable-xhdpi 
5.drawable-xlarge-mdpi 
6.drawable-xxhdpi 

and make all layout respectively then your app is going fine on any mobile tablet blue stack AOC android device 

if u go with java code then 
    int density= getResources().getDisplayMetrics().densityDpi; 

    if(density==DisplayMetrics.DENSITY_HIGH) 
          System.out.println("Density is high"); 

         if(density==DisplayMetrics.DENSITY_XXHIGH) 
          System.out.println("Density is xxhigh"); 

         if(density==DisplayMetrics.DENSITY_XXXHIGH) 
          System.out.println("Density is xxxhigh"); 

         if(density==DisplayMetrics.DENSITY_TV) 
          System.out.println("Density is Tv"); 

if(widthDp==600) 
        { 
         imageWidth = ; 
         imgHeight = ; 
         margin = ; 
        } 
        else if (widthDp==720) 
        { 

        } 
        else if(density==DisplayMetrics.DENSITY_XHIGH) 
        { 
         imageWidth = ; 
         imgHeight = ; 
         margin = ; 
        } 
        else if(density==DisplayMetrics.DENSITY_LOW) 
        { 
         imageWidth = ; 
         imgHeight = ; 
         margin = ; 
        } 
        else if(density==DisplayMetrics.DENSITY_MEDIUM) 
        { 
         imageWidth = ; 
         imgHeight = ; 
         margin = ; 
        } 
        else 
        { 
         imageWidth = ; 
         imgHeight = ; 
         margin = ; 
        } 

do what ever way u like :) 
BEST OF LUCK DUDE :) 
+0

如果ip ut mdpi,ldpi中不同大小的圖像,那麼我也必須這樣做? – user2930808

+0

是的,親愛的把所有圖像放在可繪製的文件夾中,並根據屏幕尺寸進行所有佈局:)你必須爲resd文件夾中的所有屏幕支持 –

+0

做到這一點,我必須首先爲layout-hdpi文件夾創建layout-mdpi文件夾,那? – user2930808

0

對於屏幕的兼容性,我們可以創建一個類似的佈局,大,佈局小下res文件夾的文件夾並粘貼每個文件夾中的所有佈局,並根據屏幕大小調整。 關於圖標,我們需要製作不同大小的圖標並將其放入相應的文件夾中。

+0

好,所以它有ldpi,mdpi,hdpi。 xhdpi,xxhdpi所以我必須爲所有人創建文件夾?所有佈局的名稱必須相同?它將如何檢測?我怎麼知道哪個設備是哪個設備,比如哪個設備是平板電腦,哪個設備是s4?只做不同大小的圖像和圖標不起作用? – user2930808

+0

當我們在eclipse中創建android項目時,它會自動在res文件夾下創建drawable-hdpi,mdpi,hdpi,xhdpi文件夾。並且還有一個佈局文件夾,默認情況下所有的佈局都會在那裏。 如果你想要屏幕兼容性,然後在res文件夾下創建佈局大小的文件夾,然後從默認文件夾複製所有佈局,並將其複製到大布局文件夾,然後根據屏幕大小調整文本大小,位置等。 – Anandhu

+0

但我想知道nexus7,galaxy nexus和10.1in WXGA都在xhdpi中?或在不同? – user2930808

0

嘗試使用dimen.xml文件。在那裏,你可以定義不同的屏幕尺寸值

/res/values/dimen.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <dimen name="margin_top">600dp</dimen> 
</resources> 

/res/values-large/dimen.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <dimen name="margin_top">800dp</dimen> 
</resources> 

並在您的佈局中使用

android:layout_marginTop="@dimen/margin_top" 
+0

所以我必須爲每個創建文件夾? hdpi? mdpi? ldpi?以及它會如何檢測? – user2930808

+0

編號來自hdpi,mdpi,ldpi文件夾的資源是由屏幕密度選取的。對於屏幕尺寸,您有「小」,「正常」,「大」和「xlarge」。查看此鏈接瞭解更多信息 - http://developer.android.com/guide/practices/screens_support.html – mihail