繁体   English   中英

Android中的屏幕兼容性问题

[英]Screen Compatibility issues in android

我是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最高的提示,但这仅适用于平板电脑,不适用于大屏幕手机。

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 :)

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

尝试使用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"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM