2011-11-16 5 views
0

Est-ce que quelqu'un sait ce que cela causerait?Espacement incohérent entre les onglets

enter image description here

enter image description here

J'ai créé une mise en page d'onglet personnalisé et je veux soit l'espacement ou non, juste la cohérence. Idéalement, je ne voudrais pas d'espacement, mais j'ai lu que peut ne pas fonctionner avec la barre d'action d'Android.

Voici le code xml J'utilise:

public class Tabs extends TabActivity { 

private static final Properties properties = Properties.getInstance(); 
TabHost mTabHost; 

public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.tabs); 

    mTabHost = getTabHost(); 

    addTab(getString(R.string.text_tabs_1), R.drawable.listing_tab_active, new Intent(this, Main.class), R.drawable.listing_tab_inactive); 
    addTab(getString(R.string.text_tabs_2), R.drawable.keyword_tab_active, new Intent(this, Keywords.class), R.drawable.keywords_tab_inactive); 
    addTab(getString(R.string.text_tabs_3), R.drawable.saved_tab_active, new Intent(this, Saved.class), R.drawable.saved_tab_inactive); 
} 

private void addTab(String label, int drawableId, Intent intent, int imageId) 
{ 
    TabHost.TabSpec spec = mTabHost.newTabSpec(label); 

    View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tabs_bg, getTabWidget(), false); 

    ((TextView)tabIndicator.findViewById(R.id.tabText)).setText(label); 

    ((ImageView)tabIndicator.findViewById(R.id.tabImage)).setImageResource(imageId); 

    spec.setIndicator(tabIndicator); 
    spec.setContent(intent); 

    mTabHost.addTab(spec);  
} 
} 

tabs.xml

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="0dp"> 

    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="0dp" 
    /> 

    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="0dp" 
    /> 

</LinearLayout> 
</TabHost> 

tabs_bg.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="0dip" 
android:layout_height="55dip" 
android:layout_weight="1" 
android:orientation="vertical" 
android:padding="5dp" 
android:background="@drawable/tab_bg_selector" 
> 
<ImageView android:id="@+id/tabImage" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:scaleType="center" 
    android:layout_alignParentTop="true" 
    android:paddingBottom="18dip" 
/> 
<TextView android:id="@+id/tabText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:textColor="@drawable/tab_text_selector" 
    android:gravity="center_vertical|center_horizontal" 
    android:textSize="12dip" 
/> 
</RelativeLayout> 

tab_bg_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

<!-- Active tab --> 
<item android:state_selected="true" android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/tab_bg_selected" /> 

<!-- Inactive tab --> 
<item android:state_selected="false" android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/tab_bg_unselected" /> 

<!-- Pressed tab --> 
<item android:state_pressed="true" android:drawable="@drawable/tab_bg_focused" /> 

<!-- Selected tab (using d-pad) --> 
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_bg_focused" /> 

</selector> 

tab_bg_selected.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 

<gradient android:startColor="#A8A8A8" android:centerColor="#7F7F7F" android:endColor="#696969" android:angle="-90" /> 

</shape> 

tab_bg_unselected.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 

<gradient android:startColor="#5C5C5C" android:centerColor="#424242" android:endColor="#222222" android:angle="-90" /> 

</shape> 

tab_bg_focused.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

<item android:state_pressed="true" android:padding="0dp"> 
    <shape> 
     <gradient 
      android:startColor="#E77A26" 
      android:endColor="#E77A26" 
      android:angle="270" /> 
     <stroke 
      android:width="3dp" 
      color="#0F58A7" /> 

    </shape> 
</item> 

<item android:state_focused="true" android:padding="0dp"> 
    <shape> 
     <gradient 
      android:endColor="#0F58A7" 
      android:startColor="#0F58A7" 
      android:angle="270" /> 
     <stroke 
      android:width="3dp" 
      color="#0F58A7" /> 
    </shape> 
</item> 

<item android:padding="0dp"> 
    <shape> 
     <gradient 
      android:endColor="#0F58A7" 
      android:startColor="#0F58A7" 
      android:angle="270" /> 
     <stroke 
      android:width="3dp" 
      color="#0F58A7" /> 
    </shape> 
</item> 
</selector> 

Répondre

0

Hack vos propres onglets avec quelque chose comme ceci:

<?xml version="1.0" encoding="utf-8"?> 
<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"> 

    <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="#FFFFFF"> <!-- android:padding="5dp" --> 

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


       android:layout_weight="1"/> 

     <!--<FrameLayout--> 
       <!--android:id="@+id/realtabcontent"--> 
       <!--android:layout_width="fill_parent"--> 
       <!--android:layout_height="wrap_content"--> 
       <!--android:layout_weight="1"/>--> 

     <LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:orientation="horizontal"> 
      <Button android:id="@+id/tab1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/tab1_selector" /> 
      <Button android:id="@+id/tab2" 
        android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/tab2_selector" /> 
      <Button android:id="@+id/tab3"  android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/tab3_selector" /> 
      <Button android:id="@+id/tab4" android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/tab4_selector" /> 
      <Button android:id="@+id/tab5" android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/tab5_selector" /> 

     </LinearLayout> 


     <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="0" 
       android:visibility="gone"/> 

    </LinearLayout> 

</TabHost> 
0

Je l'ai compris. Ajouter android: background = "@ drawable/tab_bg_selector" à TabWidget a fixé l'espacement:

<TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="0dp" 
     android:background="@drawable/tab_bg_selector" 
    /> 
Questions connexes