android - How to programmatically display a view in center of another view -


i have buttonview1 , customview1 draws small circle. in main_layout buttonview1 visible.

how can programmatically display customview1 in center of buttonview1 when button clicked.

attention: dont want change button background. want show new view (customview or other view edittext) on view (button) when button pressed.


layout code:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context=".mainactivity" >      <button         android:id="@+id/buttonview1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_alignparenttop="true"         android:layout_marginleft="102dp"         android:layout_margintop="86dp"         android:text="@string/button_text" />  </relativelayout> 

activity code

    ///...         protected void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);             setcontentview(r.layout.activity_main);             mbutton = (button)findviewbyid(r.id.buttonview1);             mbutton.setonclicklistener(this);         }          @override         public void onclick(view v) {             switch (v.getid()) {             case r.id.buttonview1:                 // sth here                 break;              default:                 break;             }          } ///... 

relativelayout.layoutparams layoutparams =      (relativelayout.layoutparams)positivebutton.getlayoutparams(); layoutparams.addrule(relativelayout.center_in_parent, relativelayout.true); yourview.setlayoutparams(layoutparams); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -