2013-10-31 69 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