<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sagar Waghmare on Medium]]></title>
        <description><![CDATA[Stories by Sagar Waghmare on Medium]]></description>
        <link>https://medium.com/@sagarwaghmare07?source=rss-4761b3519a49------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NU058GJqRt4uEt-mArappw.jpeg</url>
            <title>Stories by Sagar Waghmare on Medium</title>
            <link>https://medium.com/@sagarwaghmare07?source=rss-4761b3519a49------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 23:38:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sagarwaghmare07/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The power of — “Digital Detox”]]></title>
            <link>https://medium.com/@sagarwaghmare07/the-power-of-digital-detox-92dfe6593ce6?source=rss-4761b3519a49------2</link>
            <guid isPermaLink="false">https://medium.com/p/92dfe6593ce6</guid>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[health]]></category>
            <category><![CDATA[overweight]]></category>
            <category><![CDATA[motivation]]></category>
            <category><![CDATA[digital-detox]]></category>
            <dc:creator><![CDATA[Sagar Waghmare]]></dc:creator>
            <pubDate>Sat, 19 Sep 2020 16:31:00 GMT</pubDate>
            <atom:updated>2020-10-06T17:30:50.605Z</atom:updated>
            <content:encoded><![CDATA[<h3>The power of — “Digital Detox”</h3><p>There are a plenty of posts of explaining what Digital Detox is. This post is all about what phenomenal changes your life will have after being “Digitally Detoxed” and how to get there.</p><p>One important thing to note here is — “Digital Detox” should not mean giving up on your phone/laptop. It should let you decide when you to use your phone/laptop and how much to use it.</p><p>Before we look into how it changed my life, we should look into what my life was all about.</p><p>Being a Software Engineer for a very long time, digital medium was a very crucial part of my life. I would spent at least 14–15 hours a day on digital items, be it the work laptop or the phone.</p><p>When I got up in the “Afternoon”, I would check my phone for notifications, emails, messages and would then jump to Facebook and YouTube. Unknowingly I would spend at least an hour on the bed looking at my phone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xI0oRAmQ0LKSQAb7" /><figcaption>Photo by <a href="https://unsplash.com/@stereophototyp?utm_source=medium&amp;utm_medium=referral">Sara Kurfeß</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Would spent rest of the afternoon and evening looking at the work laptop. After the work was done — which usually got late at night (due to the fact that I started working late) I would get back to my phone and look at Facebook, YouTube and other so-called “Cool” apps. After spending a couple of hours on the phone, would go to bed “early in the morning”.</p><p>There were a lot of problems due to such bad lifestyle:</p><ol><li>Didn’t have any time for anything else. My life was just switching between the phone and the laptop.</li><li>Had no “me” time — no time for workout (gained a lot of weight), no time for self improvement — all my time was sucked up by the phone.</li><li>Had no family time — as I spent a lot of my time on phone — had to spend rest of my time working.</li><li>Started screwing up work items — as I didn’t have time to plan things.</li></ol><p>Once I implemented “”Digital Detox” in my life — my life changed dramatically.</p><ol><li>Now I wake up early in the morning (6am) and go for a jog, workout — helped me shed a lot of weight and improved my health.</li><li>Got a lot of “me” time — I could finally got time to read books (which I was planning to do for ever).</li><li>Got a lot of family time — I could now spend time with my kids without worrying about the work.</li><li>Got a lot of thinking time — where I can plan my work, my self goals etc. and spent time on achieving them. One of the end result is this post — written in the “me” time.</li></ol><p>How did I achieve “Digital Detox” and what techniques you can use to have a healthy “Digital Detox”:</p><ol><li>This is one of the most important thing I follow — and you guys also follow: <strong>Keep your phone away from your bedroom. </strong>Studies show that most people have a habit to spend a lot of their time looking at the phone before sleeping. This not only kills your sleeping ability (due to blue light), it makes us spend a lot of time using our favorite apps (Netflix, YouTube, Prime etc). When we keep our phone near to our bed, we will unknowingly use it and ruin the night.</li><li><strong>Mute your phone’s app notifications at night.</strong> This is very important as WhatsApp, Facebook notifications will distract you and would force your mind to look at it. Don’t worry about missing important things— as people would call you if that is really important.</li><li><strong>Don’t look at your phone notifications as soon as you wake up. </strong>This is very important for working people as any ugly email will screw your entire day. It is also very likely that you won’t be able to concentrate on your meditation/workout due to this. This will also trick your mind to spend time on the “cool” apps (YouTube, Facebook) from your phone and screw your entire schedule.</li><li>During weekends, when you have loads of free time — spend time doing new things like <strong>Start reading books, learn to cook, explore nature, do something for self-improvement </strong>instead of using your phone.</li></ol><p>In short, unleash the power of “Digital Detox” and see how it dramatically makes your life much better.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92dfe6593ce6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating pixel perfect UI for different screen sizes in Android]]></title>
            <link>https://medium.com/@sagarwaghmare07/creating-pixel-perfect-ui-for-different-screen-sizes-in-android-173ea5ffe2df?source=rss-4761b3519a49------2</link>
            <guid isPermaLink="false">https://medium.com/p/173ea5ffe2df</guid>
            <category><![CDATA[multiple-screen-sizes]]></category>
            <category><![CDATA[pixel-perfect]]></category>
            <category><![CDATA[raja-software-labs]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Sagar Waghmare]]></dc:creator>
            <pubDate>Mon, 02 Oct 2017 21:36:01 GMT</pubDate>
            <atom:updated>2017-12-09T17:45:44.280Z</atom:updated>
            <content:encoded><![CDATA[<p>Creating pixel perfect UI is tricky on Android since there are a lot of different screen sizes and resolutions to support. Android developers need to support different screen densities/sizes but the UX team most likely delivers pixel perfect UI designed for iPhones. This article is useful to Android UI developers who already know basic UI development and are aware of the basic Android support (see <a href="https://developer.android.com/training/multiscreen/index.html">https://developer.android.com/training/multiscreen/index.html</a>).<br>While the SDK documentation describes how to manage UI for different screen sizes (like phone and tablet and devices with different screen densities), this document offers a more practical approach and deals with devices that have the same screen density, but still have different screen sizes.</p><h4><strong>Problems creating pixel perfect UI in Android</strong></h4><p>Since Android supports lots of devices with variable screen sizes the problem starts right from the UX design phase. The UX guys are not sure how to create a UX design spec that will cover all the screen sizes. So, they either create specs for iOS with all the details marked in pixels and points and ask the Android developers to follow the specs. OR they will pick a Android screen (say of Nexus 5), create the spec for this device with pixels and points and will ask the Android developers to create UI which matches for all other screens.</p><p>For Android developers it is more difficult task, first they have to interpret the iOS/Android specs to Android, translating all the pixels values to <em>dp</em> values OR sometimes percentage of screen, translate pt values to <em>sp</em> and so on.</p><p>Now let’s try to fix the problem by looking at an example.</p><h4>Example 1: When the screen has horizontal constraint to be fixed. The screen can scroll vertically</h4><p>Below is an example of the specs provided by an UX designer.Here is an iOS screen spec provided with all the measurements specified in pixels and all the text sizes specified in points. In Android we need to convert this pixels to dp and points to sp.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/0*DPJThemZoSrUSHAX." /></figure><p>Here are the tips/steps on how we can create pixel perfect UI for Android even with iOS specs.</p><h4>Tip 1: Have some knowledge on the iOS/Android available screen sizes</h4><p>Now since the specs provided for us can be of iOS/Android, we should have some knowledge on the iOS/Android available screen sizes. So that, when we get the specs for a screen, we know which screen size the UX designer is using for creating UX specs. This is useful for deciding the sizes of the views in Android. In our example, the UX designer has used iOS 5 with screen size 640px x 1136px.</p><h4>Step 1: Decide which Views can be fixed size and which Views cannot be fixed</h4><p>In most of the cases the app screen has to be fixed horizontally while it can scroll vertically (if there is content which doesn’t fit in the available height). So for such cases where we do not have any constraint on the height, we need to make the horizontal UI pixel perfect as far as possible. Now, from the above iOS specs, we can see that the ImageView (which shows the chrome icon) needs to be fixed size (width and height). This Image takes around 85% of the available screen width. The Text and Button Views are to be fixed in width and can be variable at their height. They will take the vertical space as much as they want.</p><h4>Step 2: Set the View sizes/margins in the Android app</h4><p>Setting the View sizes/margins can be done using 2 approaches:</p><h4>Approach 1: Setting the View sizes programmatically</h4><p>By using this approach we will calculate the sizes of the Views programmatically at runtime and set them. In our example, we can see that the Image actually occupies around 88% of the total width. So, we will calculate the expected image width for the current device screen width and set this new size to the ImageView. Also calculate the margins between these views and set that as well.</p><p>Define the Image to the Screen ratio:</p><pre>// The Image uses 88% of the screen width<br>private static final float IMAGE_SCREEN_WIDTH_RATIO = 0.88f;</pre><p>Calculate the ImageView size and Margins:</p><pre>// Get the actual screen width<br>int screenWidth = getScreenWidth();</pre><pre>// Calculate the new image size<br>int imageViewSize = (int) ((float) screenWidth * IMAGE_SCREEN_WIDTH_RATIO);</pre><pre>// Calculate the margin<br>int margin = (screenWidth — imageViewSize) / 2;</pre><p>Set this new size to the ImageView and TextViews before the UI is rendered:</p><pre>// Set the Image size<br>LinearLayout.LayoutParams params = (LayoutParams) mImageView.getLayoutParams();</pre><pre>// Setting the same size for Width and height<br>params.height = imageViewSize;<br>params.width = imageViewSize;</pre><pre>// Set the margin’s<br>params.topMargin = margin;<br>params.bottomMargin = margin;<br>mImageView.requestLayout();</pre><pre>// Set the Header Tv margin<br>params = (LayoutParams) mHeaderTv.getLayoutParams();<br>params.bottomMargin = margin;<br>mHeaderTv.requestLayout();</pre><pre>// Set the Sub Header Tv margin<br>params = (LayoutParams) mSubHeaderTv.getLayoutParams();<br>params.bottomMargin = margin;<br>mSubHeaderTv.requestLayout();<br>int marginBetweenBtns = margin / 2;</pre><pre>// Set the Cancel Button margin<br>params = (LayoutParams) mCancelBtn.getLayoutParams();<br>params.rightMargin = marginBetweenBtns;<br>mCancelBtn.requestLayout();</pre><pre>// Set the Send Button margin<br>params = (LayoutParams) mSendBtn.getLayoutParams();<br>params.leftMargin = marginBetweenBtns;<br>mSendBtn.requestLayout();</pre><p>Here is the XML definition for this layout:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;ScrollView xmlns:android=&quot;<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>&quot;<br>  android:layout_width=&quot;match_parent&quot;<br>  android:layout_height=&quot;match_parent&quot;<br>  android:background=&quot;#aaaaaa&quot;&gt;</pre><pre>&lt;LinearLayout<br>    android:id=&quot;@+id/screen_container&quot;<br>    android:layout_width=&quot;wrap_content&quot;<br>    android:layout_height=&quot;wrap_content&quot;<br>    android:layout_gravity=&quot;center_horizontal&quot;<br>    android:orientation=&quot;vertical&quot;&gt;</pre><pre>&lt;ImageView<br>      android:id=&quot;@+id/image_view&quot;<br>      android:layout_width=&quot;match_parent&quot;<br>      android:layout_height=&quot;match_parent&quot;<br>      android:background=&quot;<a href="http://twitter.com/drawable/chrome_icon">@drawable/chrome_icon</a>&quot; /&gt;</pre><pre>&lt;TextView<br>      android:id=&quot;@+id/header_text&quot;<br>      android:layout_width=&quot;match_parent&quot;<br>      android:layout_height=&quot;wrap_content&quot;<br>      android:text=&quot;Header fontsize — 25&quot;<br>      android:textSize=&quot;25sp&quot; /&gt;</pre><pre>&lt;TextView<br>      android:id=&quot;@+id/subheader_text&quot;<br>      android:layout_width=&quot;match_parent&quot;<br>      android:layout_height=&quot;wrap_content&quot;<br>      android:text=&quot;Text fontsize — 17&quot;<br>      android:textSize=&quot;17sp&quot; /&gt;</pre><pre>&lt;LinearLayout<br>      android:id=&quot;@+id/button_container&quot;<br>      android:layout_width=&quot;match_parent&quot;<br>      android:layout_height=&quot;wrap_content&quot;<br>      android:orientation=&quot;horizontal&quot;&gt;</pre><pre>&lt;Button<br>        android:id=&quot;@+id/cancel_btn&quot;<br>        android:layout_width=&quot;0dp&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:layout_weight=&quot;1&quot;<br>        android:background=&quot;#ffffffff&quot;<br>        android:text=&quot;Cancel&quot;<br>        android:textColor=&quot;#007Aff&quot;<br>        android:textSize=&quot;15sp&quot; /&gt;</pre><pre>&lt;Button<br>        android:id=&quot;@+id/send_btn&quot;<br>        android:layout_width=&quot;0dp&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:layout_weight=&quot;1&quot;<br>        android:background=&quot;#ffffffff&quot;<br>        android:text=&quot;Send&quot;<br>        android:textColor=&quot;#007Aff&quot;<br>        android:textSize=&quot;15sp&quot; /&gt;<br>    &lt;/LinearLayout&gt;<br>  &lt;/LinearLayout&gt;<br>&lt;/ScrollView&gt;</pre><p>Here is the screen shot of the same UX design on Android using this approach:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*b8J7aQlkYqFj12Ae." /></figure><p>The advantage of using this approach is that the UI will look consistent across all the devices. It will consume the same percentage of screen on all the devices. But to achieve this, we need to relayout the Views when the new sizes are computed.</p><h4>Approach 2: Using predefined values for margins/padding etc</h4><p>In our example, the iOS specs specifies the margins to be 40px. Now, for Android we can use a predefined formula for calculating the <em>dp</em> values. For example, in our case we can use the formula <em>1dp=2px</em>. (This formula has to be decided by the developers based on some trial and error methods, depending on which formula fits best for our need). So when the specs specify as 40px, we will set the value as 20dp and so on. This approach is simpler than the earlier approach, since, for most of the places we need to set the value at compile time and that too in the XML layout file.</p><p>Here is the XML definition for this layout:</p><pre>&lt;ScrollView xmlns:android=”<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>&quot;<br> xmlns:tools=”<a href="http://schemas.android.com/tools">http://schemas.android.com/tools</a>&quot;<br> android:layout_width=”match_parent”<br> android:layout_height=”match_parent”<br> android:background=”#aaaaaa” &gt;</pre><pre>&lt;LinearLayout<br> android:id=”@+id/screen_container”<br> android:layout_width=”wrap_content”<br> android:layout_height=”wrap_content”<br> android:layout_gravity=”center_horizontal”<br> android:orientation=”vertical” &gt;</pre><pre>&lt;ImageView<br> android:id=”@+id/image_view”<br> android:layout_width=”match_parent”<br> android:layout_height=”match_parent”<br> android:layout_marginBottom=”20dp”<br> android:layout_marginTop=”20dp”<br> android:background=”<a href="http://twitter.com/drawable/chrome_icon">@drawable/chrome_icon</a>” /&gt;</pre><pre>&lt;TextView<br> android:id=”@+id/header_text”<br> android:layout_width=”match_parent”<br> android:layout_height=”wrap_content”<br> android:layout_marginBottom=”20dp”<br> android:text=”Header fontsize — 25&quot;<br> android:textSize=”25sp” /&gt;</pre><pre>&lt;TextView<br> android:id=”@+id/subheader_text”<br> android:layout_width=”match_parent”<br> android:layout_height=”wrap_content”<br> android:layout_marginBottom=”20dp”<br> android:text=”Text fontsize — 17&quot;<br> android:textSize=”17sp” /&gt;</pre><pre>&lt;LinearLayout<br> android:id=”@+id/button_container”<br> android:layout_width=”match_parent”<br> android:layout_height=”wrap_content”<br> android:orientation=”horizontal” &gt;</pre><pre>&lt;Button<br> android:id=”@+id/cancel_btn”<br> android:layout_width=”0dp”<br> android:layout_height=”wrap_content”<br> android:layout_marginRight=”10dp”<br> android:layout_weight=”1&quot;<br> android:background=”#ffffffff”<br> android:text=”Cancel”<br> android:textColor=”#007Aff”<br> android:textSize=”15sp” /&gt;</pre><pre>&lt;Button<br> android:id=”@+id/send_btn”<br> android:layout_width=”0dp”<br> android:layout_height=”wrap_content”<br> android:layout_marginLeft=”10dp”<br> android:layout_weight=”1&quot;<br> android:background=”#ffffffff”<br> android:text=”Send”<br> android:textColor=”#007Aff”<br> android:textSize=”15sp” /&gt;<br> &lt;/LinearLayout&gt;<br> &lt;/LinearLayout&gt;<br>&lt;/ScrollView&gt;</pre><p>Even using this approach is not sufficient for our design, so we need to set the ImageView size programmatically as done earlier.</p><p>Here is the screen shot of the same UX design on Android using this approach:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HbZJJYPlS75kllMA." /></figure><p>The advantage of using this approach is that the implementation is quiet simple, but the disadvantage is that the UI will look bit different on various screen sizes based on its pixel density.</p><p>The best way to manage UI for different screen sizes is to use both the above approaches wherever required. For screens, which don’t have much images and have TextView’s use the XML approach and on screens which have ImageView’s use the programmatic approach.</p><h4>Step 3: Set the TextView text size</h4><p>When specifying text size for Android Views, it is recommended to specify it in <em>sp</em> (scaled pixels). When we use <em>sp</em>, the android system takes care of scaling the text size appropriately based on the device and based on the user preference of Text Size setting. But when we get the specs, it is possible that the specs mention the text size in points (pt) i.e in the iOS style. <br> For Android, the general formula for pt to sp conversion is 1sp = 1pt. But this too depends on the font we use. So, if for some font using <em>1sp = 1pt</em> formula looks too small, we can use the formula like <em>(n sp = n + 1pt)</em>.</p><h4>Example 2: When the screen has both horizontal and vertical constraint to be fixed</h4><p>Here is an example of a screen that needs to be designed. This specs specifies that the cool-stuff shown in the center of the screen (with white background), should always be properly shown. It should not be scaled/squeezed from and side. While it also specifies that we need to maintain a minimum margin of 40px.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*qQZGCCjThrm5v7sl." /></figure><p>Creating pixel perfect UI when both the width and height are fixed is more complex and tricky. Every screen has different solutions, but follow the same below approach.</p><h4>Approach: Setting the View sizes programmatically</h4><p>By using this approach we will calculate the sizes of the Views programmatically at runtime and set them. In our example, we can see that the cool-stuff needs to be present in the center of the screen and that too cannot scale or squeeze. So, this is what we will do:</p><ul><li>Get the cool-content size shown in the spec. We will need it to resize the cool-content stuff on the screen keeping its aspect ratio same.</li><li>Get the space available on screen to layout our cool-stuff. This is done by using OnPreDrawListener.</li><li>Calculate the maximum size we can set on the cool-stuff content and set it.</li></ul><p>Define the Cool-Stuff Content ratio:</p><pre>// The Cool-Stuff content ratio<br>private static final float COOL_CONTENT_DIMENS = 688f / 1056f;</pre><p>In the XML definition, add a parent View to our cool-stuff content which will give us our available size.</p><p>In the below XML code, screen_container is the parent to our cool-stuff view layout. Here we make sure that the cool-stuff content is initially gone and will make it visible when the correct height is set. This will make sure that the UI won’t flicker when the size changes.</p><pre>&lt;?xml version=”1.0&quot; encoding=”utf-8&quot;?&gt;<br>&lt;FrameLayout xmlns:android=”<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>&quot;<br> android:id=”@+id/screen_container”<br> android:layout_width=”match_parent”<br> android:layout_height=”match_parent”<br> android:background=”#aaaaaa”<br> android:padding=”10dp”&gt;</pre><pre>     &lt;LinearLayout<br>         android:id=”@+id/cool_content_layout”<br>         android:layout_width=”match_parent”<br>         android:layout_height=”match_parent”<br>         android:layout_gravity=”center”<br>         android:background=”<a href="http://twitter.com/drawable/cool_content">@drawable/cool_content</a>”<br>         android:orientation=”vertical”<br>         android:visibility=”gone” /&gt;<br>&lt;/FrameLayout&gt;</pre><p>Get the space available on the screen for the cool-content</p><pre>mScreenContainer.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {</pre><pre><a href="http://twitter.com/Override">@Override</a><br> public boolean onPreDraw() {<br>  // Available height for cool-stuff<br>  int height = mScreenContainer.getHeight();<br>  if (height &gt; 0) {<br>   // Available Width for cool-stuff<br>   int width = mScreenContainer.getWidth();</pre><pre>computeCoolContentDimens(width, height);</pre><pre>// Don&#39;t forget to remove the PreDrawListener<br> mScreenContainer.getViewTreeObserver().removeOnPreDrawListener(this);<br>  }<br>  return true;<br> }<br>});</pre><p>When we get the screen size available for our cool-content, we compute the size of the cool-stuff layout.</p><h4>Compute the size of the cool-content based on the available size</h4><p>If we scale the cool-content width, it is still possible that the new scaled height goes beyond the available size. So, we need to first scale the width, check if the height is still in the limits. If yes, set the size. But if the height doesn’t fit in the limits, scale the height of the cool-content based on the available height. This is how it can be done.</p><pre>// Try to match the cool stuff to the available width first<br>int coolStuffHeight = (int) ((float) availableWidth / COOL_CONTENT_DIMENS);<br>// If the new height is within the available screen height, set it<br>if (coolStuffHeight &lt;= availableHeight) {<br> setCoolContentDimens(availableWidth, coolStuffHeight);<br>}<br>// If not, calculate the new cool width, this will have width surely<br>// less then available width<br>else {<br> int coolStuffWidth = (int) ((float) availableHeight * COOL_CONTENT_DIMENS);<br> setCoolContentDimens(coolStuffWidth, availableHeight);<br>}</pre><h4>Set the size of the cool-content based on the computed size</h4><p>Before setting the size we will make the view visible and then will set the size using the layout params.</p><pre>mCoolContentView.setVisibility(View.VISIBLE);<br>RelativeLayout.LayoutParams params = (LayoutParams) mCoolContentView.getLayoutParams();<br>params.width = width;<br>params.height = height;<br>mCoolContentView.requestLayout();</pre><p>The below screenshots are taken from a Nexus device. Fig a. shows the UI rendered without and dynamic computations. We can clearly see that the text is stretched. While Fig b. shows the approach of dynamic size calculation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cZ7BgW3xTnpP7D3s." /></figure><h4>Working with RecyclerView’s</h4><p>When working with RecyclerView’s (i.e adapter views), it’s always better to use fixed size ImageView’s in the RecyclerView rows (using XML approach). If we try to use the programmatic approach, we would need to set the ImageView size for each new View and that will slow down the entire layout process.</p><h4>Pixel-Perfect UI in the WebView</h4><p>There are a number of options you can use to create the perfect UI, this article will outline some of the best practices for the mobile web in general and then some specific tricks you could use for hybrid applications.</p><h4>Viewport</h4><p>The viewport meta tag is of the most important tags you need to add to your web app. Without it, the WebView may act as if your site is designed for desktop browsers. This causes your web page to be given a larger width (typically 980px) and scales it to fit the WebView’s width. In most cases, the result is a tiny overview version of the page that requires the user to pan and zoom to actually read content, like the image on the left.</p><p>If you want the width of your site to be 100% of the WebView’s width, as shown on the right, you need to set the viewport meta tag:</p><pre>&lt;meta name=”viewport” content=”width=device-width, initial-scale=1&quot;&gt;</pre><p>Setting width to the special value device-width will give you more control over the page layout.</p><p>By default the WebView will set the viewport to device-width, rather than defaulting to a desktop viewport. However, for reliable and controlled behaviour it’s good practice to include the viewport meta tag.</p><p>In some cases, you may need to display content that isn’t designed for mobile devices — for example, if you’re displaying content you don’t control. In this case, you need to force the WebView to use a desktop-size viewport:</p><pre>setUseWideViewPort(true)<br>setLoadWithOverviewMode(true)</pre><p>If these methods are not set and no viewport is specified, the WebView will try and set the viewport width based on the content size.</p><p>In addition to doing this, you may want to use the new layout algorithm <em>TEXT_AUTOSIZING</em> introduced in Android 4.4, which increases the font size to make it more readable on a mobile device.</p><h4>Summary</h4><p>To summarise the above document, for creating pixel perfect UI for different screen sizes, we need to decide which views need to be fixed sized and apply the XML/Programmatic approach best suited for that screen.</p><blockquote>I’m currently working on some cool stuff in Android at <a href="http://www.rajasoftwarelabs.com/">Raja Software Labs, Pune</a>.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=173ea5ffe2df" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>