Home:ALL Converter>Supporting multiple screens in android in single layout

Supporting multiple screens in android in single layout

Ask Time:2014-03-06T18:00:38         Author:Muhammad Salman Farooq

Json Formatter

I have followed the following link so that my application can support different screen sizes:

Supporting multiple screens in android

That solution works perfectly. But my concern here is, when I have an android application having 8-9 screens, then it means that I will have 8-9 different .xml layout files. Now to support all screens by folder bifurcation , it means I have manage almost above fifty xml files for layouts and for a simple change in UI, I have to go to all the folders and implement that change in xml file. So can there be a better way , I mean such a layout that can just resize the controls by itself or something like that?

Author:Muhammad Salman Farooq,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/22220962/supporting-multiple-screens-in-android-in-single-layout
Kanwaljit Singh :

I think this is not too complex. Create all layouts in layout folder. Use styles.xml, dimens.xml and strings.xml to save font size and strings. When your layout finalize i.e no changes required, then copy all these layouts from layout folder and paste in layout-small, layout-large, layout-xlarge. So when you need to change strings, style and font size you have to make changes in only values folders.\n\nFor example-\n\nInstead of android:text=\"Hello\" use android:text=\"string/hello\" and save value of hello in strings.xml. Similarly for text size android:textSize=\"@dimen/btxt\".\n\nThis is one of the best alternative.",
2014-03-06T10:20:51
Elhanan Mishraky :

I created a relative size unit.\nThis size unit can be used in order to build one layout xml file for all screen.\nThis size unit is available by linking the sdp sdk.\nHere is an example of a layout XML built using this sdk:\n\n<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\nxmlns:tools=\"http://schemas.android.com/tools\"\nandroid:layout_width=\"match_parent\"\nandroid:layout_height=\"match_parent\"\nandroid:background=\"@android:color/white\"\nandroid:gravity=\"center\">\n<LinearLayout\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:orientation=\"vertical\">\n\n <LinearLayout\n android:id=\"@+id/give_us_a_review_landmine_main_layout\"\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:gravity=\"center\"\n android:orientation=\"vertical\"\n android:paddingBottom=\"@dimen/_27sdp\"\n android:paddingLeft=\"@dimen/_43sdp\"\n android:paddingRight=\"@dimen/_43sdp\"\n android:paddingTop=\"@dimen/_50sdp\" >\n\n <TextView\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:text=\"Intuit\"\n android:textColor=\"@android:color/black\"\n android:textSize=\"@dimen/_40sdp\"/>\n\n <LinearLayout\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:layout_marginTop=\"@dimen/_minus10sdp\"\n android:paddingBottom=\"@dimen/_15sdp\"\n android:orientation=\"horizontal\" >\n\n <TextView\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:includeFontPadding=\"false\"\n android:text=\"♡\"\n android:textColor=\"#ED6C27\"\n android:textSize=\"@dimen/_70sdp\"\n android:textStyle=\"bold\" />\n\n <TextView\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:includeFontPadding=\"false\"\n android:text=\"U\"\n android:textColor=\"@android:color/black\"\n android:textSize=\"@dimen/_70sdp\" />\n </LinearLayout>\n\n <TextView\n android:id=\"@+id/give_us_a_review_landmine_text_1\"\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:gravity=\"center\"\n android:paddingBottom=\"@dimen/_12sdp\"\n android:text=\"Rate us so we can grow and help more people get their finances in check\"\n android:textColor=\"@android:color/black\"\n android:textSize=\"@dimen/_16sdp\" />\n\n <TextView\n android:id=\"@+id/give_us_a_review_landmine_text_2\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"wrap_content\"\n android:gravity=\"center\"\n android:text=\"★★★★★\"\n android:textColor=\"#747474\"\n android:textSize=\"@dimen/_22sdp\"\n android:textStyle=\"bold\" />\n\n <Button\n android:id=\"@+id/give_us_a_review_landmine_button\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"wrap_content\"\n android:layout_gravity=\"center\"\n android:layout_marginTop=\"@dimen/_25sdp\"\n android:padding=\"@dimen/_8sdp\"\n android:text=\"Rate\"\n android:textSize=\"@dimen/_15sdp\"\n android:visibility=\"visible\"\n android:textColor=\"@android:color/white\"\n android:gravity=\"center\"\n android:minWidth=\"120dp\"\n android:includeFontPadding=\"false\"\n android:background=\"#0ac775\"\n android:singleLine=\"true\" />\n\n </LinearLayout>\n</LinearLayout>\n\n\n\n\nAnd here is the result:\n\n\n\nNote that the UI elements scales with the screen size.",
2015-02-19T10:40:58
yy