Relative Layout Programmatically <p>I have a relative layout which consists a <code>Button</code> a <code>EditText</code></p> <p>At the time of page loading I am initializing the relative layout like this </p> <pre><code>RelativeLayout bottomLayout; bottomLayout = (RelativeLayout) findViewById(R.id.s_r_l_bottom); RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) bottomLayout .getLayoutParams(); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, -1); bottomLayout.setLayoutParams(layoutParams ); </code></pre> <p>As a result my relative layout was at the bottom of the screen. Now what I am trying that I also have <code>Button</code> on the top the screen .</p> <p>By pressing the button I want that the relative layout will be on the center of the screen</p> <p>For that I have used the following code on button click(The code is executing.I have tested that).But it did not help me.</p> <pre><code>RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) bottomLayout.getLayoutParams(); layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, -1); bottomLayout.setLayoutParams(layoutParams); </code></pre> <p>Can you please help me out to fix this?</p>