2011-03-02 18 views

Respuesta

3

Puede añadir esto a diseño xml android:gravity="center" o android:layout_gravity="center"

+1

agrego esto en tabhost o pestaña widegt o framlayout. ?? por favor dígame esto .. –

+0

Si agrega el android: layout_gravity = "center", el diseño principal estará centrado pero si usa android: layout_gravity = "center", las vistas secundarias estarán centradas. Las vistas secundarias son el elemento dentro de su diseño. Por ejemplo, el diseño lineal es su elemento primario mientras que dentro del diseño lineal define las vistas secundarias, como el botón y la vista de texto. – exception01

+0

@exception donde agregar este android: layout_gravity = "center"? a TabLayout? No funciona para mí, ¿puedes responder? También no puedo dar 'android: gravedad' a TabLayout –

32

Si alguien sigue interesado en una solución sencilla sin crear propio diseño y estilos:

  1. Uso android.widget.TabHost.TabSpeC# setIndicator (CharSequence etiqueta) para cada ficha añadido
  2. Use el código siguiente para centrar y ajustar el texto dentro de la pestaña:

    int tabCount = tabHost.getTabWidget().getTabCount(); 
    for (int i = 0; i < tabCount; i++) { 
        final View view = tabHost.getTabWidget().getChildTabViewAt(i); 
        if (view != null) { 
         // reduce height of the tab 
         view.getLayoutParams().height *= 0.66; 
    
         // get title text view 
         final View textView = view.findViewById(android.R.id.title); 
         if (textView instanceof TextView) { 
          // just in case check the type 
    
          // center text 
          ((TextView) textView).setGravity(Gravity.CENTER); 
          // wrap text 
          ((TextView) textView).setSingleLine(false); 
    
          // explicitly set layout parameters 
          textView.getLayoutParams().height = ViewGroup.LayoutParams.FILL_PARENT; 
          textView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT; 
         } 
        } 
    } 
    
+0

Perfecto !!! gracias! –

+0

¡Gracias! ayuda mucho –

+0

Impresionante ..... +1 –

0

¡¡Pruebe esto, será de ayuda para usted !!!

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/tabhost" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:padding="1dp" > 

     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 

<TabWidget 
    android:id="@android:id/tabs" 
    android:layout_width="fill_parent" 
    android:layout_height="60dp" 
    android:layout_alignParentBottom="true" /> 

<FrameLayout 
    android:id="@android:id/tabcontent" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="1dp" > 
</FrameLayout> 
0
<android.support.design.widget.TabLayout 
app:tabMode="fixed" 
app:tabContentStart="0dp" 
Cuestiones relacionadas