title: Set runtime margin to any view using Kotlin
body: <p>I am a beginner in Kotlin .I am not too much familier with this language. I am making one example and playing with code. I Just want to set runtime margin to any view. I also trying to google it but not getting any proper solution for this task.</p>
  
  <p><strong>Requirement</strong></p>
  
  <p>Set runtime margin to any View.</p>
  
  <p><strong>Description</strong></p>
  
  <p>I have taking one xml file which is contain on Button and I want to set runtime margin to this button.</p>
  
  <p><strong>Code</strong></p>
  
  <p>I also try below thing but it's not work.</p>
  
  <pre><code>class MainActivity : AppCompatActivity() {
  
  
  //private lateinit var btnClickMe: Button
  //var btnClickMe=Button();
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
          //For setting runtime text to any view.
          btnClickMe.text = "Chirag"
  
          //For getting runtime text to any view
          var str: String = btnClickMe.text as String;
  
          //For setting runtimer drawable
         btnClickMe.background=ContextCompat.getDrawable(this,R.drawable.abc_ab_share_pack_mtrl_alpha)//this.getDrawable(R.drawable.abc_ab_share_pack_mtrl_alpha)
  
  
          /*
          //For Setting Runtime Margine to any view.
          var param:GridLayout.LayoutParams
          param.setMargins(10,10,10,10);
  
          btnClickMe.left=10;
          btnClickMe.right=10;
          btnClickMe.top=10;
          btnClickMe.bottom=10;
          */
  
          // Set OnClick Listener.
          btnClickMe.setOnClickListener {
              Toast.makeText(this,str,5000).show();
          }
  
      }
  
  }
  </code></pre>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:orientation="vertical"
  tools:context="chirag.iblazing.com.stackoverflowapp.MainActivity"
  android:layout_height="match_parent"&gt;
  
  &lt;Button
      android:id="@+id/btnClickMe"
      android:text="Click Me"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>How can I proceed?</p>