title: Centering a button programmatically
body: <p>I am trying to programmatically create a centered button that would print a word when pressed.
  I have used Gravity for this, however I am getting 2 errors:</p>
  
  <pre><code>eglSurfaceAttrib not implemented
  Failed to set EGL_SWAP_BEHAVIOR on surface 0xae0ee360, error=EGL_SUCCESS
  </code></pre>
  
  <p>Below is my code:</p>
  
  <pre><code>import android.support.v7.app.ActionBarActivity;
  import android.os.Bundle;
  import android.view.Gravity;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Button;
  import android.widget.FrameLayout;
  
  
  public class MainActivity extends ActionBarActivity {
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.menu_main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      int id = item.getItemId();
  
      if (id == R.id.action_settings) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  
  /////////////
  
  @Override
  protected void onCreate(Bundle bundle) {
  
      super.onCreate(bundle);
      setContentView(R.layout.activity_main);
  
      final ViewGroup vg1 = (ViewGroup) findViewById(android.R.id.content);
      float w1 = vg1.getWidth();
      float h1 = vg1.getHeight();
  
      final Button b1 = new Button(this);
  
      b1.setText("");
  
      float left = (w1 - vg1.getWidth())/2;
      float top = (h1 - vg1.getHeight())/2;
  
      FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams((int)w1/2, (int)h1/2);
      layoutParams.setMargins( (int)left,  (int)top, (int)(left+w1/2), (int)(top+h1/2));
      layoutParams.gravity = Gravity.CENTER;
  
      b1.setLayoutParams(layoutParams);
      vg1.addView(b1, layoutParams);
  
      b1.setOnClickListener(new View.OnClickListener(){
          @Override
          public void onClick(View v) {                
                  b1.setText("TestTest");
          }
      });
  }
  </code></pre>
  
  <p>and the xml:</p>
  
  <pre><code>&lt;FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  </code></pre>
  
  <p></p>
  
  <p>Please, help me find my mistake.
  I just started learning android development, not really experienced in this.</p>
  
  <p>Thank you!</p>