title: Setting padding programmatically and through xml
body: <p>I'm creating some custom components and I would like to have a default padding set, but also be able to configure it through xml if so desired. </p>
  
  <p><strong>For example:</strong> </p>
  
  <p>Simple custom TextView component with default padding: </p>
  
  <pre><code>class MyComponent @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) : TextView(context, attrs, defStyle) {
  
  init {
          layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
  
          val verticalPadding = resources.getDimension(R.dimen.FourDp).toInt()
          val horizontalPadding = resources.getDimension(R.dimen.FourDp).toInt()
          setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding)
      }
  }
  </code></pre>
  
  <p>This component would then be dropped into the app as: </p>
  
  <pre><code>&lt;com.example.components.MyComponent
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="padding test"
                      &lt;!-- setting padding is optional --&gt; 
                      android:paddingTop="32dp"/&gt;
  </code></pre>
  
  <p><strong>The Question</strong></p>
  
  <p>Android currently ignores the 32dp of padding set through xml and goes with the four dp of padding that's in the component's <code>init</code> method. Is there a way that I can get Android to use the padding set in xml if it exists, and use the default padding if no such padding is specified in xml? </p>