J'utilise xml pour dessiner un indicateur de progression en rotation avec du texte. Au bas de l'écran, j'ai un TableLayout avec deux boutons, qui sont centrés dans la page avec chaque texte également centré.Le bouton Android perd l'alignement du texte après setText
<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>
Dans le code que j'ai un runnable que, après quelques secondes modifie le texte sur la TextView de progress_text.
private Runnable mTimeTask = new Runnable() {
public void run() {
TextView progressText = (TextView) findViewById(R.id.progress_text);
progressText.setText("Second text");
}
};
Le problème est que, après cette setText(), une fois que je me concentre sur l'un des boutons, le texte perd son alignement centré et va tout le chemin à gauche. Qu'est-ce que je fais mal?
J'ai rencontré ce problème mais le texte du bouton devenait aligné en bas. J'ai posté un nouveau Q & A ici avec ma solution, ce qui impliquait de cacher et d'afficher le bouton. http://stackoverflow.com/questions/28514288/buttons-text-gets-wrong-alignment-after-a-settext-call-on-a-textview –