0

我是 android 新手,我正在开发应用程序。我在developers.google.com 中读到,如果我希望应用程序屏幕兼容,那么我的图标应该是ldpi、mdpi、hdpi、xhdpi 和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>

所以,你看这里我给了margin top,但这仅适用于平板电脑,不适用于大屏幕手机。

4

3 回答 3

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 :)
于 2013-10-31T12:30:26.737 回答
0

为了屏幕兼容性,我们可以在 res 文件夹下创建 layout-large、layout-small 等文件夹并将所有布局粘贴到每个文件夹中并根据屏幕大小进行调整。关于图标,我们需要制作不同大小的图标并将其放在相应的文件夹中。

于 2013-10-31T12:33:43.183 回答
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"
于 2013-10-31T12:34:27.073 回答