2013-02-07 4 views
4

Je veux mettre tabwidget sur le fond comme iPhone App. Je sais ce que cette mise en page est contre la directive Google UserInterface, mais j'ai besoin.Comment mettre FragmentTabhost en bas

ainsi, j'ai lu beaucoup de poste similaire dans Stackoverflow. mais chaque article ne fonctionne pas.

Je veux utiliser FragmentTabhost, sans utiliser la bibliothèque externe (ex: ActionBarSherlock

ceci est mon code

<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/tabhost" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

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

    <FrameLayout 
     android:id="@+id/tabcontent" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_above="@android:id/tabs" /> 

    <FrameLayout 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_above="@android:id/tabs" /> 

    <TabWidget 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="horizontal" /> 
</RelativeLayout> 

et code d'activité est inférieure à

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_top); 

    //set up FragmentTabhost 
    FragmentTabHost host = (FragmentTabHost)findViewById(R.id.tabhost); 
    host.setup(this,getSupportFragmentManager(),R.id.content); 

    //add tabspec 
    TabSpec tabSpec1 = host.newTabSpec("tab1"); 
    Button btn1 = new Button(this); 
    btn1.setBackgroundResource(R.drawable.icon1); 
    tabSpec1.setIndicator(btn1); 
    Bundle bundle1 = new Bundle(); 
    bundle1.putString("name", "tab1"); 
    host.addTab(tabSpec1,SampleFragment.class,bundle1); 


    TabSpec tabSpec2 = host.newTabSpec("tab2"); 
    Button btn2 = new Button(this); 
    btn2.setBackgroundResource(R.drawable.icon2); 
    tabSpec2.setIndicator(btn2); 
    Bundle bundle2 = new Bundle(); 
    bundle2.putString("name", "tab2"); 
    host.addTab(tabSpec2,SampleFragment1.class,bundle2); 

} 

si J'ai essayé une autre disposition comme celle-ci

<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/tabhost" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <FrameLayout 
     android:id="@+id/tabcontent" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_weight="0" /> 

    <TabWidget 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     android:orientation="horizontal" /> 

    <FrameLayout 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 
</LinearLayout> 

s'il vous plaît aidez-moi,


Remarque finalement je résolu ce ploblem. Ce bug est de SupportPackage .....

essayer cette

http://code.google.com/p/android/issues/detail?id=40035

Répondre

2

Essayez ceci:

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

<TabWidget 
    android:id="@android:id/tab" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" /> 

<FrameLayout 
    android:id="@android:id/content" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 
</RelativeLayout> 
-2

Essayez cela, Après XML fonctionne pour moi très bien.

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

<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="wrap_content" 
     android:layout_alignParentBottom="true" /> 

    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
</RelativeLayout> 
</android.support.v4.app.FragmentTabHost> 

Espérons que cela fonctionnera.

+0

Désolé, ce travail ne marche pas, encore il y a onglet sur – dmnlk

+0

J'ai maintenant collé XML complet qui fonctionne bien pour moi et il met le tabhost en bas. Vérifier. –

+0

ummm ... Je remplace le xml par le vôtre, mais tabhost est top .... s'il vous plaît télécharger votre projet? – dmnlk

0

Essayez ceci:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.app.FragmentTabHost 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"> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" /> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0"/> 
    </LinearLayout> 
</android.support.v4.app.FragmentTabHost> 
+0

merci, résolu ploblem. – dmnlk

+0

toujours dans le top. – Anirban

Questions connexes