title: Android Programmatically set button layout
body: <p>Hi I'm trying to load a button into a view pager and i have it loading in but it's currently filling the entire screen i would like it it to wrap content to its exact size and then position it in the middle of the screen. i have tried to set layoutparams for the button but when i run the app it still fills parent. does anyone know how to programmatically set layout and position of a button?</p>
  
  <p>heres what i have tried so far</p>
  
  <pre><code>@Override
          public Object instantiateItem(View collection, int position) {
  
              RelativeLayout.LayoutParams rel_btn = new RelativeLayout.LayoutParams(
              LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
              rel_btn.addRule(RelativeLayout.CENTER_VERTICAL);
              rel_btn.addRule(RelativeLayout.CENTER_HORIZONTAL);
              rel_btn.height = 60;
              rel_btn.width = 60;
              Button tv = new Button(cxt);
              tv.setLayoutParams(rel_btn);
              tv.setText("League " + (position+1));
              tv.setTextColor(Color.WHITE);
              tv.setTextSize(30);
              tv.setBackgroundDrawable(getResources().getDrawable(R.drawable.ls_level_eng1));
  
              ((ViewPager) collection).addView(tv,0);
  
              return tv;
          }
  </code></pre>