{"id":1386,"date":"2016-02-03T12:09:46","date_gmt":"2016-02-03T12:09:46","guid":{"rendered":"http:\/\/www.mplx.de\/Fremdgesteuert\/?p=1386"},"modified":"2019-09-04T04:43:41","modified_gmt":"2019-09-04T04:43:41","slug":"layouts-for-android-apps","status":"publish","type":"post","link":"http:\/\/www.mplx.de\/Fremdgesteuert\/2016\/02\/03\/layouts-for-android-apps\/","title":{"rendered":"Layouts for Android Apps"},"content":{"rendered":"<div id=\"attachment_1393\" style=\"width: 179px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.mplx.de\/Fremdgesteuert\/2016\/02\/03\/layouts-for-android-apps\/start-screen\/\" rel=\"attachment wp-att-1393\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1393\" class=\"wp-image-1393 size-medium\" src=\"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/Fitness-Manager-start-screen-169x300.png\" alt=\"Fitness Manager start screen\" width=\"169\" height=\"300\" srcset=\"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/Fitness-Manager-start-screen-169x300.png 169w, http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/Fitness-Manager-start-screen.png 540w\" sizes=\"auto, (max-width: 169px) 100vw, 169px\" \/><\/a><p id=\"caption-attachment-1393\" class=\"wp-caption-text\">Fitness Manager start screen<\/p><\/div>\n<p align=\"JUSTIFY\">Unfortunately our awesome, great, incredible, wonderful and joyful travel year is over now. So we have to work and earn money to hopefully continue this experience soon. So I started to program and develop my first Android App. I want to write about the difficulties I ran into while developing my apps. Therefore I have to switch the language of my blog to English and the blog is obviously getting technical. I want to apologize for both. Ok, let&#8217;s start and have a look to Layouts for Android Apps.<\/p>\n<p align=\"JUSTIFY\">My first App is called &#8216;Fitness Manager&#8217; and the app is available for all kind of Apple IOS Devices and for many many different Android Devices. The App provides the user with useful features and functions around planning workout sessions in the gym. The start screen of the app leads the user to different main functionalities like &#8216;Create a workout schedule&#8217; or &#8216;View statistics&#8217; and to further sub tasks like &#8216;Upload data to the cloud&#8217;. In order to get this looking good in my eyes on every device I had to take a lot of issues into account.<\/p>\n<p align=\"JUSTIFY\">You can embed LinearLayouts in GridLayouts or you can use TableLayouts surrounded by FrameLayouts. You have depending on the choosen layout several different layout options which you can set. The posibilities concerning the layouts are incredible. But you only have three possible values in the layout.xml to set the <em>layout_width<\/em> and the <em>layout_height<\/em> of every view item: <em>match_parent<\/em>, <em>wrap_content<\/em> or a fixed value. I wanted to insert a logo, an advertise view element, four big ImageButtons for the main functionalities and 4 small ImageButtons for the sub tasks into the start screen like displayed in the above image. And that&#8217;s how layout.xml for the start screen looks like:<\/p>\n<ol>\n<li>\n<p align=\"JUSTIFY\">All view elements are embedded in a GridLayout with only one column but 5 rows.<\/p>\n<p><div id=\"attachment_1389\" style=\"width: 571px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.mplx.de\/Fremdgesteuert\/2016\/02\/03\/layouts-for-android-apps\/grid-layout\/\" rel=\"attachment wp-att-1389\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1389\" class=\"wp-image-1389 size-full\" src=\"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/GridLayout.png\" alt=\"GridLayout of Fitness Manager start screen\" width=\"561\" height=\"108\" srcset=\"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/GridLayout.png 561w, http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/GridLayout-300x58.png 300w\" sizes=\"auto, (max-width: 561px) 100vw, 561px\" \/><\/a><p id=\"caption-attachment-1389\" class=\"wp-caption-text\">GridLayout of Fitness Manager start screen<\/p><\/div><\/li>\n<\/ol>\n<ol start=\"2\">\n<li>\n<p align=\"JUSTIFY\">The logo is inserted in the first row of the GridLayout and the advertise view (not displayed in the image above) in the second row. In order to center the logo and the advertise view in every device the <i>layout_gravity<\/i> of <u>every<\/u> view element has to be set to <i>center<\/i>.<\/p>\n<\/li>\n<\/ol>\n<ol start=\"3\">\n<li>\n<div id=\"attachment_1391\" style=\"width: 437px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.mplx.de\/Fremdgesteuert\/2016\/02\/03\/layouts-for-android-apps\/linear-layout-logo\/\" rel=\"attachment wp-att-1391\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1391\" class=\"wp-image-1391 size-full\" src=\"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/LinearLayout-Logo.png\" alt=\"Logo embedded in LinearLayout\" width=\"427\" height=\"309\" srcset=\"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/LinearLayout-Logo.png 427w, http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/LinearLayout-Logo-300x217.png 300w\" sizes=\"auto, (max-width: 427px) 100vw, 427px\" \/><\/a><p id=\"caption-attachment-1391\" class=\"wp-caption-text\">Logo embedded in LinearLayout<\/p><\/div>\n<p align=\"JUSTIFY\">In the next rows of the GridLayout I did insert the ImageButtons for the main functionalities and the sub tasks. For every row I added one LinearLayout which spreads over the complete width of the screen and then I inserted two to four LinearLayouts which contain the ImageButtons. In order to get the design flexible I did work with the settings <i>layout_sum<\/i> and <i>layout_weight.<\/i> The <i>layout_sum<\/i> is set in the outer LinearLayout. The <i>layout_weight<\/i> is defined in the inner LinearLayouts. The sum of the <i>layout_weights<\/i> is defined in the <i>layout_sum<\/i>. Again I had to <i>center<\/i> <u>every<\/u> view element. The <i>orientation<\/i> of the outer LinearLayout is defined <i>horizontal<\/i> whereas the <i>orientation<\/i> of the inner LinearLayout is set to <i>vertical<\/i>.<\/p>\n<div id=\"attachment_1390\" style=\"width: 297px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.mplx.de\/Fremdgesteuert\/2016\/02\/03\/layouts-for-android-apps\/linear-layout-imagebutton\/\" rel=\"attachment wp-att-1390\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1390\" class=\"wp-image-1390 size-medium\" src=\"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/LinearLayout-ImageButton-287x300.png\" alt=\"ImageButton embedded in LinearLayouts\" width=\"287\" height=\"300\" srcset=\"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/LinearLayout-ImageButton-287x300.png 287w, http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/LinearLayout-ImageButton.png 531w\" sizes=\"auto, (max-width: 287px) 100vw, 287px\" \/><\/a><p id=\"caption-attachment-1390\" class=\"wp-caption-text\">ImageButton embedded in LinearLayouts<\/p><\/div>\n<p align=\"JUSTIFY\">I want to point out the meaning of the LinearLayout orientation here because in the beginning my design looked like displayed below also I had centered every single element. The failure was the orientation of the inner LinearLayouts which was defined horizontal. Maybe this implementation issue is obvious for many many other Android developers but I&#8217;m a blonde developer and so I write this for all the blond programmers out there. It almost drove me nuts and I couldn&#8217;t find a hint in the internet why my design looked so shitty until I had a close look to the orientation of the LinearLayouts.<\/p>\n<p><div id=\"attachment_1392\" style=\"width: 512px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.mplx.de\/Fremdgesteuert\/2016\/02\/03\/layouts-for-android-apps\/shitty-start-screen\/\" rel=\"attachment wp-att-1392\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1392\" class=\"wp-image-1392 size-full\" src=\"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/Shitty-Start-screen.png\" alt=\"Shitty start screen of Fitness Mangager App displayed in Android Studio Tablet emulator\" width=\"502\" height=\"854\" srcset=\"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/Shitty-Start-screen.png 502w, http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/Shitty-Start-screen-176x300.png 176w\" sizes=\"auto, (max-width: 502px) 100vw, 502px\" \/><\/a><p id=\"caption-attachment-1392\" class=\"wp-caption-text\">Shitty start screen of Fitness Mangager App displayed in Android Studio Tablet emulator<\/p><\/div><\/li>\n<\/ol>\n<ol start=\"4\">\n<li>\n<p align=\"JUSTIFY\">At least I had to adapt the layout progammatically in the corresponding Java File because in the designer of the Android Studio the view was displayed like shown below and moreover the sizes of the ImageButtons needed to be fitted to the different screen sizes of available Android devices:<\/p>\n<div id=\"attachment_1388\" style=\"width: 336px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.mplx.de\/Fremdgesteuert\/2016\/02\/03\/layouts-for-android-apps\/android-studio-designer\/\" rel=\"attachment wp-att-1388\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1388\" class=\"wp-image-1388 size-full\" src=\"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/Android-Studio-Designer.png\" alt=\"Fitness Manager start screen displayed in Android Studio Designer\" width=\"326\" height=\"580\" srcset=\"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/Android-Studio-Designer.png 326w, http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/Android-Studio-Designer-169x300.png 169w\" sizes=\"auto, (max-width: 326px) 100vw, 326px\" \/><\/a><p id=\"caption-attachment-1388\" class=\"wp-caption-text\">Fitness Manager start screen displayed in Android Studio Designer<\/p><\/div>\n<p align=\"JUSTIFY\">If you want to change the sizes of different view elements dependent on the size of other view elements, you cannot implement the changes in the <em>onCreate<\/em> or <em>onResume<\/em> funtions of an activity. The drawing phase of the view, which provides the measurements of the single view elements is only finished at the end of <em>onResume<\/em> function. Therefore I added runnables to the layout queue which will be invoked after the call of <em>setContentView<\/em> when all view measurements are finished. In these runnables I could request the width and height of single view elements, the <em>DisplayMetrics<\/em> of the Android device and set the <em>LayoutParams<\/em> of the ImageButtons.<\/p>\n<p><div id=\"attachment_1394\" style=\"width: 871px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.mplx.de\/Fremdgesteuert\/2016\/02\/03\/layouts-for-android-apps\/view-runnable\/\" rel=\"attachment wp-att-1394\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1394\" class=\"wp-image-1394 size-full\" src=\"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/ImageButton-Runnable.png\" alt=\"ImageButton Runnable\" width=\"861\" height=\"527\" srcset=\"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/ImageButton-Runnable.png 861w, http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/ImageButton-Runnable-300x184.png 300w, http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/ImageButton-Runnable-768x470.png 768w, http:\/\/www.mplx.de\/Fremdgesteuert\/wp-content\/uploads\/2016\/01\/ImageButton-Runnable-588x360.png 588w\" sizes=\"auto, (max-width: 861px) 100vw, 861px\" \/><\/a><p id=\"caption-attachment-1394\" class=\"wp-caption-text\">ImageButton Runnable<\/p><\/div><\/li>\n<\/ol>\n<p align=\"JUSTIFY\">If you have any questions concerning my layout design and implementation, any improvement suggestions for the implementation (I mentioned that this is my first Android App) or any improvement suggestions for my English, I really would appreciate if you can leave me a comment.<\/p>\n<p align=\"JUSTIFY\">And I would even more appreciate if you like to check out the <a href=\"https:\/\/play.google.com\/store\/apps\/details?id=de.mplx.fitnessmanager&amp;hl=de\">&#8216;Fitness Manager&#8217; App in the Google Play Store<\/a> or the <a href=\"https:\/\/itunes.apple.com\/us\/app\/fitness-manager\/id447600109?l=de&amp;ls=1&amp;mt=8\">&#8216;Fitness Manager&#8217; App in the iTunes Store<\/a>. See you.<\/p>\n<p align=\"JUSTIFY\">Follow us on<br \/>\n<a href=\"https:\/\/www.facebook.com\/Fitness-Manager-106773422758349\">Facebook<\/a><br \/>\n<a href=\"https:\/\/twitter.com\/FitnessManager_\">Twitter<\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/100472904065361948117\">Google Plus<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unfortunately our awesome, great, incredible, wonderful and joyful travel year is over now. So we have to work and earn money to hopefully continue this experience soon. So I started to program and develop my first Android App. I want to write about the difficulties I ran into while developing my apps. Therefore I have [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[392],"tags":[394,419,420,421,422,395,404,393,405,400,399,398],"class_list":["post-1386","post","type-post","status-publish","format-standard","hentry","category-android-app-development","tag-android","tag-android-gridlayout","tag-android-linearlayout","tag-android-linearlayout-orientation","tag-android-runnable-post","tag-android-studio","tag-app","tag-fitness-manager","tag-java","tag-layout_gravity","tag-layout_sum","tag-layout_weight"],"_links":{"self":[{"href":"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-json\/wp\/v2\/posts\/1386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-json\/wp\/v2\/comments?post=1386"}],"version-history":[{"count":21,"href":"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-json\/wp\/v2\/posts\/1386\/revisions"}],"predecessor-version":[{"id":1477,"href":"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-json\/wp\/v2\/posts\/1386\/revisions\/1477"}],"wp:attachment":[{"href":"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-json\/wp\/v2\/media?parent=1386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-json\/wp\/v2\/categories?post=1386"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mplx.de\/Fremdgesteuert\/wp-json\/wp\/v2\/tags?post=1386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}