{"id":14666,"date":"2014-07-11T13:09:08","date_gmt":"2014-07-11T07:39:08","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=14666"},"modified":"2014-07-11T13:09:08","modified_gmt":"2014-07-11T07:39:08","slug":"handle-multiple-screen-sizes-in-android","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/handle-multiple-screen-sizes-in-android\/","title":{"rendered":"Handle Multiple Screen Sizes in Android"},"content":{"rendered":"<p style=\"text-align: justify\">Android devices come in a variety of screen sizes and resolutions. That&#8217;s why handling the multiple screen size in android is most important.<\/p>\n<p style=\"text-align: center\"><span class=\"highlight\"><strong>TERMS AND CONCEPTS<\/strong><\/span><\/p>\n<p style=\"text-align: justify\"><strong>Screen size :<\/strong> Actual physical size, measured as the screen&#8217;s diagonal.For simplicity, Android groups has four generalized sizes: small, normal, large, and extra large.<\/p>\n<p style=\"text-align: justify\"><strong><del><\/del>Screen density :<\/strong> The quantity of pixels within a physical area of the screen; usually referred to as dpi (dots per inch).For simplicity, Android groups has four generalized densities: low, medium, high, and extra high.<\/p>\n<p style=\"text-align: justify\"><strong>Orientation :<\/strong>\u00a0 The orientation of the screen from the user&#8217;s point of view.In Android, This is either landscape or portrait.<\/p>\n<p style=\"text-align: justify\"><strong>Resolution :<\/strong> The total number of physical pixels on a screen.In Android, we do not work directly with resolution; applications should be concerned only with screen size and density.<\/p>\n<p align=\"center\"><span class=\"highlight\"><strong>How To Support Different Screen&#8217;s.<\/strong><\/span><\/p>\n<p>Basically we are mainly this things by three ways.<br \/>\n<strong>1.<\/strong> Explicitly declare in the manifest which screen sizes your application supports.<br \/>\n<strong>2.<\/strong> Provide different layouts for different screen sizes.<br \/>\n<strong>3.<\/strong> Provide different bitmap drawables for different screen densities.<\/p>\n<p style=\"margin-bottom: 0cm;line-height: 100%;text-align: left\"><span class=\"highlight\"><b>1. Explicitly declare in the manifest which screen sizes your application supportss<\/b><\/span><\/p>\n<p style=\"margin-bottom: 0cm;line-height: 100%;text-align: justify\">To set up support for multiple device sizes in Android, add the <span style=\"color: #0000ff\">&lt;support-screens&gt; <\/span>element into the AndroidManifest.xml file. This field specifies which screen size support and which do not.<\/p>\n<p>[xml]<br \/>\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br \/>\n&lt;manifest ..&gt;<\/p>\n<p>&lt;supports-screens<br \/>\nandroid:smallScreens=&quot;true&quot;<br \/>\nandroid:normalScreens=&quot;true&quot;<br \/>\nandroid:largeScreens= &quot;true&quot;<br \/>\nandroid:anyDensity=&quot;true&quot;<br \/>\n\/&gt;<\/p>\n<p>&lt;application&#8230; &gt;<br \/>\n\u2026.<br \/>\n&lt;\/application&gt;<br \/>\n&lt;\/manifest&gt;<br \/>\n[\/xml]<\/p>\n<p style=\"margin-bottom: 0cm;line-height: 100%\">we can also define dp in the <span style=\"color: #0000ff\">&lt;support-screens&gt; <\/span>element like-<\/p>\n<p>[xml]<br \/>\n&lt;manifest &gt;<br \/>\n    &lt;supports-screens android:requiresSmallestWidthDp=&quot;600&quot; \/&gt;<br \/>\n&lt;\/manifest&gt;<br \/>\n[\/xml]<\/p>\n<p style=\"margin-bottom: 0cm;line-height: 100%\"><span class=\"highlight\"><b>2. Provide different layouts for different screen sizes<\/b><\/span><\/p>\n<p style=\"margin-bottom: 0cm;line-height: 100%;text-align: justify\">As we design our UI for different screen sizes, we&#8217;ll discover that each design requires a minimum amount of space. So, each generalized screen size above has an associated minimum resolution that&#8217;s defined by the system. These minimum sizes are in &#8220;dp&#8221; units.<\/p>\n<p>[java]<br \/>\nres\/layout\/my_layout.xml             \/\/ layout for normal screen size (&quot;default&quot;)<br \/>\nres\/layout-small\/my_layout.xml       \/\/ layout for small screen size<br \/>\nres\/layout-large\/my_layout.xml       \/\/ layout for large screen size<br \/>\nres\/layout-xlarge\/my_layout.xml      \/\/ layout for extra large screen size<br \/>\nres\/layout-xlarge-land\/my_layout.xml \/\/ layout for extra large in landscape orientation<br \/>\n[\/java]<\/p>\n<p style=\"margin-bottom: 0cm;line-height: 100%\">We can also define it on the basis of dp like &#8211;<\/p>\n<p>[java]<br \/>\nres\/layout\/main_activity.xml           \/\/ For handsets<br \/>\nres\/layout-sw600dp\/main_activity.xml   \/\/ For 7\u201d  tablets(600&#215;1024 mdpi).600dp wide and bigger.<br \/>\nres\/layout-sw720dp\/main_activity.xml   \/\/ For  10\u201d tablets (720&#215;1280 mdpi).720dp wide and bigger.<br \/>\n[\/java]<\/p>\n<p style=\"margin-bottom: 0cm;line-height: 100%\"><span class=\"highlight\"><b>3. Provide different bitmap drawables for different screen densities<\/b><\/span><\/p>\n<p style=\"margin-bottom: 0cm;line-height: 100%;text-align: justify\">To set labels for different layouts, dimensions or different screen density resources, use the following resource directories:<\/p>\n<p style=\"margin-bottom: 0cm;line-height: 100%\"><a href=\"\/blog\/wp-ttn-blog\/uploads\/2014\/07\/Aug13_handling01.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-14709 aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2014\/07\/Aug13_handling01.jpg\" alt=\"Aug13_handling01\" width=\"190\" height=\"223\" \/><\/a><\/p>\n<p style=\"margin-bottom: 0cm;font-weight: normal;line-height: 100%\"><span style=\"font-size: medium\">For example:<\/span><\/p>\n<p>[java]<br \/>\nres\/drawable-hdpi\/myImg.png  \t\/\/  bitmap  used for high-density<br \/>\nres\/drawable-mdpi\/myImg.png \t\/\/  bitmap  used for medium-density<br \/>\nres\/drawable-ldpi\/myImg.png\t  \/\/ bitmap used for low-density<br \/>\nres\/drawable-xhdpi\/myImg.png       \/\/  bitmap used for extra high density<br \/>\n[\/java]<\/p>\n<p style=\"margin-bottom: 0cm;line-height: 200%\" align=\"center\"><span style=\"font-size: large\"><span class=\"highlight\"><b>Handing Screen Density<\/b><\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm;font-weight: normal;line-height: 100%;text-align: justify\"><span style=\"font-size: medium\">We can develop our application to maintains the physical size of the interface by using match_parent and wrap_content values for android:layout_width and android:layout_height. This parameter does not specify size but adapts to the space available.<\/span><\/p>\n<p>[xml]<br \/>\n&#8230;<br \/>\nandroid:layout_width = &quot;match_parent&quot;<br \/>\nandroid:layout_height = &quot;wrap_content&quot;<br \/>\n&#8230;<br \/>\n[\/xml]<\/p>\n<p style=\"margin-bottom: 0cm;font-weight: normal;line-height: 100%;text-align: justify\"><span style=\"font-size: medium\">Bitmap scaling can result in blurry images. To prevent this, provide higher-resolution bitmaps for high-density screens and the system will use those instead of resizing the bitmap designed for medium-density screens.<\/span><\/p>\n<p style=\"margin-bottom: 0cm;font-weight: normal;line-height: 100%;text-align: justify\"><span style=\"color: #ffffff\">A<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: medium\">Following are ways the Android system helps to achieve density independence:<\/span><\/p>\n<p style=\"margin-bottom: 0cm;line-height: 100%;text-align: justify\"><span style=\"font-size: medium\"><strong>1.<\/strong> <span style=\"font-weight: normal\">Android considers dp [density-independent pixels] units as appropriate for the current screen density. <\/span><\/span><\/p>\n<p style=\"margin-bottom: 0cm;font-weight: normal;line-height: 100%;text-align: justify\"><span style=\"font-size: medium\"><strong>2.<\/strong> Android also accounts for scaled pixels (sp), which are scaled based on the user&#8217;s preference of font size (FONT_SCALE value in System. Settings).<\/span><\/p>\n<p style=\"margin-bottom: 0cm;font-weight: normal;line-height: 100%;text-align: justify\"><span style=\"font-size: medium\"><strong>3.<\/strong> Android scales the drawable resources to the suitable size, if alternative resources are not available, and it solely depends on the current screen density.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Android devices come in a variety of screen sizes and resolutions. That&#8217;s why handling the multiple screen size in android is most important. TERMS AND CONCEPTS Screen size : Actual physical size, measured as the screen&#8217;s diagonal.For simplicity, Android groups has four generalized sizes: small, normal, large, and extra large. Screen density : The quantity [&hellip;]<\/p>\n","protected":false},"author":126,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":21},"categories":[518],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/14666"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/126"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=14666"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/14666\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=14666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=14666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=14666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}