2015-04-24 1 views
0

Je suis nouveau dans Android et j'implémente un tiroir de navigation, Jusqu'ici j'ai réussi à lister mes articles dans le tiroir et ai ajouté un fragment dans mon framelayout. La page d'accueil fonctionne normalement, mais lorsque j'ouvre le tiroir, les boutons de mon encadrement apparaissent sur le dessus du tiroir de navigation.Le contenu de FrameLayout apparaît sur le tiroir de navigation ci-dessus: Android

J'ai besoin de faire apparaître le framelayout sous le tiroir de navigation.

code Mon comme suit

activity_main.xml

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

    <android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.shimplyapp.MainActivity" > 


    <fragment 
     android:id="@+id/navigation_drawer" 
     android:name="com.example.shimplyapp.NavigationDrawerFragment" 
     android:layout_width="@dimen/navigation_drawer_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     tools:layout="@layout/fragment_navigation_drawer" /> 


</android.support.v4.widget.DrawerLayout> 

    <FrameLayout 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" > 


    </FrameLayout> 

</RelativeLayout> 

fragment_navigation_drawer.xml

<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="start"  
    android:choiceMode="singleChoice" 
    android:divider="@android:color/transparent" 
    android:dividerHeight="0dp" 
    android:background="@android:color/black" 
    tools:context="com.example.shimplyapp.NavigationDrawerFragment" /> 

home_default.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
    <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:layout_marginLeft="15dp" 
      android:layout_marginRight="15dp" 
      android:gravity="center" 
      android:orientation="vertical" > 

      <EditText 
       android:id="@+id/etxt_sn_enter_number" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="0dp" 
       android:hint="enter_search_ item here.." 
       android:inputType="text" 
       android:maxLength="15" 
       android:singleLine="true" /> 

      <Button 
       android:id="@+id/btn_lm_search_number" 
       android:layout_width="match_parent" 
       android:layout_height="60dp" 
       android:layout_marginTop="15dp" 
       android:text="search" 
       android:textColor="#ffffff" 
       android:textSize="20sp" 
       android:textStyle="bold" /> 

      <Button 
       android:id="@+id/btn_lm_view_stores" 
       android:layout_width="match_parent" 
       android:layout_height="60dp" 
       android:layout_marginTop="15dp" 
       android:text="store" 
       android:textColor="#ffffff" 
       android:textSize="20sp" 
       android:textStyle="bold" /> 

      <Button 
       android:id="@+id/btn_lm_view_deals" 
       android:layout_width="match_parent" 
       android:layout_height="60dp" 
       android:layout_marginTop="15dp" 
       android:text="deal" 
       android:textColor="#ffffff" 
       android:textSize="20sp" 
       android:textStyle="bold" />    
     </LinearLayout> 
</RelativeLayout> 

Voici mon fragment d'appel de MainActivity

@Override 
public void onNavigationDrawerItemSelected(int position) { 
    Fragment fragment = null; 
    FragmentManager fragmentManager; 

    //flag a global variable initially flag = 0;  

    if(flag ==0){ 
     fragment = new HomePage(); 
     fragmentManager.beginTransaction().replace(R.id.container, fragment).commit(); 
     flag = 1; 
    } 
     //..... rest is switch cases for calling different fragments 
} 
+0

lieu la mise en page de cadre au-dessus de la navigation tiroir en xml –

Répondre

1

Votre activity_main.xml devrait être comme ça .Modification et essai

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

     <android.support.v4.widget.DrawerLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:id="@+id/drawer_layout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      tools:context="com.example.shimplyapp.MainActivity" >  

     <Fragment 
      android:id="@+id/navigation_drawer" 
      android:name="com.example.shimplyapp.NavigationDrawerFragment" 
      android:layout_width="@dimen/navigation_drawer_width" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      tools:layout="@layout/fragment_navigation_drawer" /> 

     <FrameLayout 
      android:id="@+id/container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" > 
     </FrameLayout> 
    </android.support.v4.widget.DrawerLayout> 

</RelativeLayout> 
+0

Vous n'avez pas besoin de la disposition relative autour de lui mais oui c'est correct. La raison en est, une disposition de tiroir doit avoir exactement 2 enfants, l'écran principal, puis la disposition des tiroirs. Chacune de ces mises en page peut avoir des enfants si besoin. – Zamereon

+0

Bien merci pour la suggestion de ne pas garder la disposition relative, juste l'ignorer, btw quand j'ai modifié mon code dans ce nouveau 'activity_main.xml' ce qui est arrivé est, quand je balaye vers la droite, le tiroir s'ouvre, mais ne se ferme pas Je le fais glisser vers la gauche. Je dois cliquer sur la barre de menu ci-dessus pour le fermer. –

+0

Et je ne peux pas faire défiler la liste des options dans le 'Tiroir' aussi ..... AIDE .. !! –