<?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 Martelli Eliseo on Medium]]></title>
        <description><![CDATA[Stories by Martelli Eliseo on Medium]]></description>
        <link>https://medium.com/@EliseoMartelli?source=rss-9f6d103a4a23------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rOJEeqUxF_bX0WhMnOC5xw.png</url>
            <title>Stories by Martelli Eliseo on Medium</title>
            <link>https://medium.com/@EliseoMartelli?source=rss-9f6d103a4a23------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 10:36:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@EliseoMartelli/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[A Little Hack For Android Dimensions]]></title>
            <link>https://medium.com/@EliseoMartelli/a-little-hack-for-android-dimensions-9eb885140c33?source=rss-9f6d103a4a23------2</link>
            <guid isPermaLink="false">https://medium.com/p/9eb885140c33</guid>
            <dc:creator><![CDATA[Martelli Eliseo]]></dc:creator>
            <pubDate>Thu, 26 May 2016 19:59:38 GMT</pubDate>
            <atom:updated>2016-05-26T19:59:38.752Z</atom:updated>
            <content:encoded><![CDATA[<p>If you write a lot of <strong>UI</strong> layouts for <strong>Android </strong>and your goal is making a <a href="https://medium.com/google-developers/building-a-responsive-ui-in-android-7dc7e4efcbb3">responsive Android App</a>, you surely faced the need of having something like “match_parent” or “wrap_content” in your Android Dimension Resources.</p><p>You might think of typing this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*wD14kgt4YSNntMhEkLBxbg.png" /></figure><p>But it doesn’t work like this. And the compiler will let you know that <strong>it doesn’t like what you’ve typed.</strong> 😡</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*PGdZAhA-41RikTV5wBeZUw.png" /></figure><p>We’ve to go a <strong>little bit deeper</strong> and see <strong>how</strong> the Android Source Code <strong>manages LayoutParams. </strong><br>Looking to the <a href="https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/view/ViewGroup.java">source code</a> you can see that:</p><p><em>MATCH_PARENT</em> and <em>WRAP_CONTENT</em> are two <em>static final ints </em>and they’re set respectively to -1 and -2.</p><p>When you set the width or the height to a view, the <strong>value is stored in an <em>int</em></strong><em> </em>(using px as a measurement unit).</p><p><strong>Px isn’t the only measurement unit.</strong> Android uses a lot of them (dp, sp, mm) but most of them depends on other things such as the screen density. <strong>Px is density independent and this is good for us!</strong></p><p>At this point you can <strong>try putting <em>-1px </em>in place of <em>match_parent</em></strong><em> </em>in one of your layouts and it will work as expected!</p><p>Observing this we can say that:</p><ul><li><em>MATCH_PARENT</em> equals to -1px,</li><li><em>WRAP_CONTENT</em> equals to -2px.</li></ul><p>Nice, uh?</p><h3>What you can do using this trick?</h3><p>Using this trick you can build <a href="https://medium.com/google-developers/building-a-responsive-ui-in-android-7dc7e4efcbb3">responsive</a> apps exploiting the dimension resources xml file and resize things to reach your screen boundaries without recurring to Java but only using xml.</p><p><strong>Example:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*788-mHtIgkGtiUYXeM9uLA.png" /></figure><p>Go and <strong>spread the word</strong> &#39;cause we need to #BuildBetterApps!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9eb885140c33" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>