title: Code equivalent of android:cropToPadding
body: <p>In my android app, I create thumbnails in xml this way:</p>
  
  <pre><code>&lt;ImageView android:id="@+id/my_thumbnail
             android:layout_width="50dp"
             android:layout_height="50dp"
             android:background="@color/white"
             android:padding="2dp"
             android:scaleType="fitXY"
             android:cropToPadding="true" /&gt;
  </code></pre>
  
  <p>This creates a white border around the thumbnail - and looks quite nice.</p>
  
  <p>Now, in another place in the code I need to create the thumbnails in the code, not XML (this is an Adapter class for GridView - to create a grid of thumbnails).  I can set all parameters as required, however I cannot find a way to set the <code>cropToPadding</code> in the code.  As a result, the thumbnail are drawn over the padding and it looks really ugly.</p>
  
  <p>How do I set this <code>cropToPadding</code> thing in the code?</p>
  
  <p>BTW, the app must work on Android 1.6.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Following a suggestion from <em>userSeven7s</em>, I add this style to my XML containing other styles:</p>
  
  <pre><code>&lt;style name="GridImage"&gt;
      &lt;item name="android:background"&gt;@color/white&lt;/item&gt;
      &lt;item name="android:padding"&gt;2dp&lt;/item&gt;
      &lt;item name="android:cropToPadding"&gt;true&lt;/item&gt;
      &lt;item name="android:typeface"&gt;monospace&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>
  
  <p>(Note that the file contains <code>&lt;resources&gt;</code> root element and contains a couple of other <code>&lt;style&gt;</code> elements.  Yet all of the other ones are only referenced form layout xml files.)</p>
  
  <p>I then added this code inside my grid view adapter:</p>
  
  <pre><code>public View getView(int position, View convertView, ViewGroup parent) {
      ImageView imageView;
      if (convertView == null) {
          XmlPullParser parser = mContext.getResources().getXml(R.style.GridImage);
          AttributeSet attributes = Xml.asAttributeSet(parser);
          imageView = new ImageView(mContext, attributes);
          // ... some more initialisation
      } else {
          imageView = (ImageView) convertView;
      }
  
      // ... code to create the bitmap and set it into the ImageView goes here
  }
  </code></pre>
  
  <p>This compiles fine (i.e. <code>R.style.GridImage</code> exists).  However when I run this code, the app crashes with <code>Resources.NotFoundException</code> on <code>getXml(R.style.GridImage)</code>.</p>
  
  <p>Any suggestions?</p>