Android button loses text alignment after setText -


i'm using xml draw spinning progress indicator along text. in bottom of screen have tablelayout 2 buttons, centered in page each text centered.

<relativelayout         android:id="@+id/progresscontainer"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:gravity="center_horizontal">           <progressbar android:id="@+id/progress_bar"              style="?android:attr/progressbarstylesmall"              android:layout_width="wrap_content"              android:layout_height="wrap_content"             android:layout_centerinparent="true"             android:paddingright="10dp" />          <textview android:id="@+id/progress_text"              android:layout_torightof="@id/progress_bar"             android:layout_width="wrap_content"              android:layout_height="wrap_content"             android:layout_centerinparent="true"             android:text="first text" />  </relativelayout>  <tablelayout     android:id="@+id/buttonbar"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:layout_alignparentbottom="true"     android:paddingtop="3dip"     android:background="@color/buttonbar"     android:stretchcolumns="0,1">      <tablerow>          <button android:id="@+id/button1"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:text="button1" />          <button android:id="@+id/button2"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:text="button2" />      </tablerow>  </tablelayout> 

in code have runnable after couple of seconds changes text on progress_text textview.

private runnable mtimetask = new runnable() {     public void run() {        textview progresstext = (textview) findviewbyid(r.id.progress_text);        progresstext.settext("second text");    }  }; 

the problem after settext(), once focus on 1 of buttons, text loses it's centered alignment , goes way left. doing wrong?

i had problem too. seems settext() changes gravity settings, had reapply them using:

button.setgravity(gravity.center_horizontal); 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -