multiple screen support in android

后端 未结 5 670
灰色年华
灰色年华 2020-11-28 15:49

I am working on a project and i have tested it on nexus one. its working there properly but I want that my project should be compatible with all screen sizes. How to do this

相关标签:
5条回答
  • 2020-11-28 16:08

    http://developer.android.com/guide/practices/screens_support.html

    You have to add different folder for different layout in res folder --> hdpi,mdpi,ldpi and for large screens you xhdpi(for Tablet) and large-hdpi or xlarge (for NXzoom). Also set Images and text size different in different layout as per screensize...

    0 讨论(0)
  • 2020-11-28 16:12

    This guy has some great blogs about how to handle multiple screen sizes in your android applications. They're titled Handling Multiple Screen Sizes and there are 5 parts:

    http://www.androidguys.com/2010/02/16/handling-multiple-screen-sizes-part/

    http://www.androidguys.com/2010/02/18/handling-multiple-screen-sizes-part-2/

    http://www.androidguys.com/2010/02/23/handling-multiple-screen-sizes-part-3/

    http://www.androidguys.com/2010/03/01/handling-multiple-screen-sizes-part-4/

    http://www.androidguys.com/2010/03/02/handling-multiple-screen-sizes-part-5/

    Read through them and you should have a better understanding of all the things you need to do.

    0 讨论(0)
  • 2020-11-28 16:15

    i am dealing with it this way and its working fine.....if any one has improved wayso do guide me

    Screen size 480x800

    layout-normal-hdpi-480x800

    drawable-normal-hdpi-480x800

    Screen size Galaxy Nexus--- though its size is 1280x720 but in actual due to system bar its dimension(screen size) differs

    layout-normal-xhdpi

    drawable-normal-xhdpi

    Screen size Note 5.3---

    layout-normal-xhdpi-1280x800

    drawable-normal-xhdpi-1280x800

    Screen size S3---

    layout-normal-xhdpi-1280x720

    drawable-normal-xhdpi-1280x720

    Screen size 7inch tab 2 supporting OS version 3 and above--- dont write dimension 1026x600 bsz in actual due to system bar its dimension(screen size) differs

    layout-large-mdpi

    drawable-large-mdpi

    Screen size 7inch tab p1000 etc supoorting os verion less than 3---

    layout-large-hdpi-1024x600

    drawable-large-hdpi-1024x600

    Screen size 1280x800 tab 10.1,10.2,note 10.1 etc--- you can add dimension if you want other wise it is fine

    layout-xlarge-mdpi

    drawable-xlarge-mdpi

    0 讨论(0)
  • 2020-11-28 16:23

    All the answers above are great in there own means.Many times we're in scenario where our nested LinearLayout within RelativeLayout is hard to fit all the screens considering some complex layout line Tile

    The above scenario can be solved by android's percent support library fitting all the screens.

    Demo HERE

    GitHub Project HERE

    <android.support.percent.PercentRelativeLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TextView
            android:id="@+id/fifty_huntv"
            android:background="#ff7acfff"
            android:text="20% - 50%"
            android:textColor="@android:color/white"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_heightPercent="20%"
            app:layout_widthPercent="50%" />
        <TextView
            android:layout_toRightOf="@id/fifty_huntv"
            android:background="#ffff5566"
            android:text="80%-50%"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_heightPercent="80%"
            app:layout_widthPercent="50%"
            />
    </android.support.percent.PercentRelativeLayout>
    

    Hope anyone find it useful :-).

    0 讨论(0)
  • 2020-11-28 16:25

    For Old day, we used to create different layout folder such as layout-small, layout-normal, layout-large, layout-xlarge for multiple screen. But that is a hell lot of work. So there is a new way to support multiple screen. Details are given below.

    For Support Multiple Screen (All Mobiles and Tablets):

    For Mobiles : We generally using different values folders for different dpi and inside that values folders only the “dimens.xml” file is different because when we are using different devices only the dimension is changed other than that all the parameters for example colors, strings, styles etc. are same. For values folders: There are total 4 values folders.

    values                                    (For mdpi devices)
    values-hdpi                               (For hdpi devices)
    values-xhdpi                              (For xhdpi devices)
    values-xxhdpi                             (For xxhdpi devices)
    

    (here Inside each folder only dimens file is different so except dimens file, keep all other files only in values folder.)

    For Tablets : We have to use sw (smallestWidth) concept. For example sw600dp means the system will use these resources only when the smallest dimension of available screen is at least 600dp. The device’s smallestWidth does not change when the screen’s orientation changes. Generally we create two folders inside res folder for tablets:

    layout-sw600dp                       (For 7″ to 9″ Screen)
    layout-sw720dp                       (For 10″ to above screen)
    

    One last thing, Images for any device (Mobiles or Tablets) you have to create different drawable folders:

    drawable-mdpi
    drawable-hdpi
    drawable-xhdpi
    drawable-xxhdpi
    
    0 讨论(0)
提交回复
热议问题