簡體   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