2011-09-18 12 views
8

Tengo una pregunta básica. En muchos ejemplos de tabhost, encontramos pestañas con imagen y texto.¿Cómo centrar el texto en tabhost?

En mi caso, me gustaría mostrar solo un texto, pero el problema es que mi texto está centrado horizontalmente pero no verticalmente (El texto está en la parte inferior de mi pestaña).

Intenté: android: layout_gravity = "center" en el framelayout, pero no funciona.

¿Tiene alguna idea, por favor?

Mi xml.

<TabHost 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_gravity="center"> 

    <LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center"> 

     <TabWidget android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center"/> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center"> 

     </FrameLayout> 

    </LinearLayout> 

</TabHost> 

resuelto: personalicé mis pestañas gracias al siguiente tutorial: http://joshclemm.com/blog/?p=136

Gracias

+0

Es mejor utilizar una pestaña personalizada, ya que las pestañas predeterminadas tienen el tamaño de los iconos y el texto. –

+0

posible duplicado de [Cómo centrar el texto en una barra de pestañas en Android] (http://stackoverflow.com/questions/5164443/how-to-center-align-text-in-a-tab-bar-in- android) – user7116

+0

La misma pregunta fue hecha hace mucho tiempo. Lea este problema [ingrese la descripción del enlace aquí] (http://stackoverflow.com/questions/5164443/how-to-center-align-text-in-a-tab-bar-in-android) – Dimon

Respuesta

0
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:gravity="center_vertical|center_horizontal" 
android:layout_gravity="center_vertical|center_horizontal" 
+0

Intenté su solución pero no funcionaba. Mi texto aún está en la parte inferior de mi pestaña. ¿Funciona para usted? – Miroufle

+0

actualizó la respuesta, ¿lo intentó? – user634545

+0

Sí, probé ambas versiones, pero no funciona :( – Miroufle

0

Utilice el siguiente código para hacer pestaña texto en el centro:

RelativeLayout .LayoutParams param = new

RelativeLayout.Layout Params (LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

param.addRule(RelativeLayout.CENTER_IN_PARENT); 

TextView tv = (TextView) tabHost.getTabWidget().getChildAt(0) 
      .findViewById(android.R.id.title); // Unselected Tabs 
    tv.setTextColor(Color.parseColor("#505050")); 
    tv.setTextSize(10); 
    tv.setLayoutParams(param); 
3
  1. tratar de conseguir la primera títulos de las fichas y establecer la gravedad y diseños explícitamente como se muestra a continuación:

    TextView textView = (TextView)tabHost.getTabWidget().getChildAt(0) 
    .findViewById(android.R.id.title); 
    textView.setGravity(Gravity.CENTER);   
    textView.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT; 
    textView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT; 
    

    Esperanza esta ayuda.

Cuestiones relacionadas