snipt

Ctrl+h for KB shortcuts

Text only

converter units to dp margin

1
2
3
4
5
6
7
final float scale = getContext().getResources().getDisplayMetrics().density;
                                int pixels = (int) (42 * scale + 0.5f);
                                
                                
 LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(150, 150);
 layoutParams.leftMargin = pixels;
 iv_item_h.setLayoutParams(layoutParams);
https://snipt.net/embed/2195d6fe865e06f3baf4b6c55585997a/
/raw/2195d6fe865e06f3baf4b6c55585997a/
2195d6fe865e06f3baf4b6c55585997a
text
Text only
7
2019-08-20T19:34:17
True
False
False
Apr 30, 2016 at 09:54 AM
/api/public/snipt/145924/
converter-units-to-dp-margin
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>final float scale = getContext().getResources().getDisplayMetrics().density; </span><span id="L-2"><a name="L-2"></a> int pixels = (int) (42 * scale + 0.5f); </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a> LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(150, 150); </span><span id="L-6"><a name="L-6"></a> layoutParams.leftMargin = pixels; </span><span id="L-7"><a name="L-7"></a> iv_item_h.setLayoutParams(layoutParams); </span></pre></div> </td></tr></table>
android, dp, imageview, margin

Text only

margin to textView

1
2
3
                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)title_product.getLayoutParams();
                params.setMargins(0, 28, 0, 0);
                title_product.setLayoutParams(params);
https://snipt.net/embed/a8debbbcadd2de89ff25e760d9ad504b/
/raw/a8debbbcadd2de89ff25e760d9ad504b/
a8debbbcadd2de89ff25e760d9ad504b
text
Text only
3
2019-08-21T10:46:52
True
False
False
Jan 21, 2016 at 01:53 PM
/api/public/snipt/143735/
margin-to-textview
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a> LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)title_product.getLayoutParams(); </span><span id="L-2"><a name="L-2"></a> params.setMargins(0, 28, 0, 0); </span><span id="L-3"><a name="L-3"></a> title_product.setLayoutParams(params); </span></pre></div> </td></tr></table>
android, margin, textview

CSS

Natural box style

1
2
3
4
/* apply a natural box layout model to all elements */
* { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }

/* paulirish.com/2012/box-sizing-border-box-ftw/ */
https://snipt.net/embed/15dbbdd06a377e4b5d02aa5bea7e1e05/
/raw/15dbbdd06a377e4b5d02aa5bea7e1e05/
15dbbdd06a377e4b5d02aa5bea7e1e05
css
CSS
4
2019-08-21T19:51:26
True
False
False
/api/public/snipt/41946/
natural-box-style
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c">/* apply a natural box layout model to all elements */</span> </span><span id="L-2"><a name="L-2"></a><span class="o">*</span> <span class="p">{</span> <span class="o">-</span><span class="n">moz</span><span class="o">-</span><span class="n">box</span><span class="o">-</span><span class="n">sizing</span><span class="o">:</span> <span class="nb">border</span><span class="o">-</span><span class="n">box</span><span class="p">;</span> <span class="o">-</span><span class="n">webkit</span><span class="o">-</span><span class="n">box</span><span class="o">-</span><span class="n">sizing</span><span class="o">:</span> <span class="nb">border</span><span class="o">-</span><span class="n">box</span><span class="p">;</span> <span class="n">box</span><span class="o">-</span><span class="n">sizing</span><span class="o">:</span> <span class="nb">border</span><span class="o">-</span><span class="n">box</span><span class="p">;</span> <span class="p">}</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c">/* paulirish.com/2012/box-sizing-border-box-ftw/ */</span> </span></pre></div> </td></tr></table>
border-box, margin, padding, width