1

J'essaie de faire une activité contenant deux fragments. Le premier a 3 fragments imbriqués que je vais utiliser comme onglets et le second contient seulement des boutons. Je ne veux pas ajouter le fragment de boutons dans d'autres framents parce que je ne veux pas le recharger. En ce moment je n'ai pas d'erreurs mais mon fragment de boutons ne se présente pas. Voici mes fragments et mon activité.Fragment n'apparaît pas

mon activité principale:

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR); 

    setContentView(R.layout.activity_main); 

    Fragment statistics = new StatisticsFragment(); 
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 
    transaction.add(R.id.fragment_statistics, statistics).commit(); 

    Fragment buttons = new MainPageButtonsFragment(); 
    FragmentTransaction buttonsTransaction = getSupportFragmentManager().beginTransaction(); 
    buttonsTransaction.add(R.id.main_page_buttons_fragment,buttons).commit(); 

sa mise en page

<RelativeLayout android:orientation="vertical" > 
<FrameLayout 
    android:id="@+id/fragment_statistics" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 

<FrameLayout 
    android:id="@+id/main_page_buttons_fragment" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/fragment_statistics"/> 

J'écris wont mon fragment de boutons, car il ne faut pas que je dirai seulement sa balise racine est FrameLayout.

mes statistiques fragment (avec onglets)

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 

    Fragment currentDayFragment = new CurrentDayFragment(); 
    FragmentTransaction transaction1 = getChildFragmentManager().beginTransaction(); 
    transaction1.add(R.id.current_day_fragment, currentDayFragment).commit(); 

    Fragment configurationInfoFragment = new ConfigurationInfoFragment(); 
    FragmentTransaction transaction2 = getChildFragmentManager().beginTransaction(); 
    transaction2.add(R.id.configuration_info_fragment, configurationInfoFragment).commit(); 

    Fragment expensesInfoFragment = new ExpensesInfoFragment(); 
    FragmentTransaction transaction3 = getChildFragmentManager().beginTransaction(); 
    transaction3.add(R.id.expenses_info_fragment, expensesInfoFragment).commit(); 

    LayoutInflater lf = getActivity().getLayoutInflater(); 

    View statisticsView = lf.inflate(R.layout.fragment_statistics, container, false); 

    return statisticsView; 
} 

sa mise en page:

<FrameLayout > 

<android.support.v4.view.ViewPager 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <FrameLayout 
     android:id="@id/current_day_fragment" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    <FrameLayout 
     android:id="@id/configuration_info_fragment" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    <FrameLayout 
     android:id="@id/expenses_info_fragment" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

</android.support.v4.view.ViewPager> 

les fragments imbriqués ont juste balise racine FrameLayout et deux TextView s en elle. Le résultat est juste une activité avec 3 onglets et aucun fragment de boutons. Je suis nouveau à la programmation Android et je suis complètement perdu dans ce domaine. Aidez-moi, s'il vous plaît!

Répondre

0

Essayez d'utiliser la hauteur donnant sur mesure comme ça ...

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 

     <FrameLayout 
      android:id="@+id/fragment_statistics" 
      android:layout_width="fill_parent" 
      android:layout_height="250dp" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" /> 

     <FrameLayout 
      android:id="@+id/main_page_buttons_fragment" 
      android:layout_width="fill_parent" 
      android:layout_height="250dp" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_alignParentBottom="true" /> 
    </RelativeLayout> 
+0

C'est ok maintenant! Tu es l'homme! – Angel

0

disposition relative n'a pas android: orientation param

I chose première couverture deuxième fragment un

Changer la disposition relative avec LinearLayout

<LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
    <FrameLayout 
     android:id="@+id/fragment_statistics" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

    <FrameLayout 
     android:id="@+id/main_page_buttons_fragment" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/fragment_statistics"/> 
</LinearLayout> 
+0

merci @Settarxan mais ce n'est pas le problème. J'ai essayé avec LinearLayout et le résultat est le même. LinearLayout ne supporte pas non plus l'option layout_below – Angel

+0

Maintenant, votre première activité est visible mais la deuxième n'est pas oui? Vous souhaitez afficher le deuxième fragment à côté du premier en même temps? –

+0

Oui, je veux que les deux fragments s'affichent simultanément mais pas l'un à côté de l'autre. Je veux que la seconde soit en dessous de la première. Et le premier fragment contient 3 onglets que j'ai aussi implémentés en fragments. – Angel