1

J'ai cherché partout mais je n'ai pas eu ce que je voulais.Je veux montrer le menu, quand je clique sur le menu burger sur la barre d'outils

Menu Burger cliquez sur la barre d'outils, doit afficher le menu, comme le menu du tiroir de navigation, mais pas sur le côté gauche, je le veux du haut. Il doit avoir glisser vers le bas animation

voici deux photos, l'affichage ce que je veux obtenir
avant l'icône du menu, cliquez sur:

before menu icon click

après un clic:

after click

ceci est ma mise en page xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    android:orientation="vertical" 
    xmlns:android="http://schemas.android.com/apk/res/android" 

    xmlns:tools="http://schemas.android.com/tools" 

    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/white" 
    android:id="@+id/container" 
    android:focusableInTouchMode="true"> 


<!-- Toolbar --> 
<include 
    layout="@layout/toolbar" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"/> 



<!-- main container layout --> 
<LinearLayout 
    android:fitsSystemWindows="true" 
    android:background="@color/white" 
    android:focusableInTouchMode="true" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:orientation="vertical" 
    android:layout_weight="1" 
    android:layout_width="match_parent" 
    android:layout_height="0dp"> 



    <!-- content container layout--> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_weight="1" 
     android:layout_width="match_parent" 
     android:layout_height="0dp"> 

     <EditText 
      android:id="@+id/player_one_id" 
      android:hint="@string/hint_player_one" 
      android:textSize="@dimen/player_name_text_size" 
      android:imeOptions="actionDone" 
      android:textColor="@color/text_color" 
      android:textColorHint="@color/textColorHint" 
      android:layout_width="match_parent" 
      android:layout_weight="1" 
      android:layout_height="0dp"/> 



     <EditText 
      android:id="@+id/player_two_id" 
      android:textColorHint="@color/textColorHint" 
      android:hint="@string/hint_player_two" 
      android:textSize="@dimen/player_name_text_size" 
      android:imeOptions="actionDone" 
      android:textColor="@color/text_color" 
      android:layout_width="match_parent" 
      android:layout_weight="1" 
      android:layout_height="0dp"/> 


     <EditText 
      android:id="@+id/player_three_id" 
      android:textColorHint="@color/textColorHint" 
      android:hint="@string/hint_player_three" 
      android:textSize="@dimen/player_name_text_size" 
      android:imeOptions="actionDone" 
      android:textColor="@color/text_color" 
      android:layout_width="match_parent" 
      android:layout_weight="1" 
      android:layout_height="0dp"/> 


     <EditText 
      android:id="@+id/player_four_id" 
      android:textColorHint="@color/textColorHint" 
      android:hint="@string/hint_player_four" 
      android:textSize="@dimen/player_name_text_size" 
      android:imeOptions="actionDone" 
      android:textColor="@color/text_color" 
      android:layout_width="match_parent" 
      android:layout_weight="1" 
      android:layout_height="0dp"/> 




     <TextView 
      android:layout_marginTop="@dimen/margin_choose_game_type" 
      android:text="@string/switch_game_type" 
      android:textColor="@color/text_color" 
      android:textSize="@dimen/text_view_size" 
      android:layout_width="wrap_content" 
      android:layout_weight="0.5" 
      android:layout_height="0dp"/> 


     <Spinner 
      android:id="@+id/spinner_game_mode_id" 
      android:layout_marginTop="@dimen/spinner_margin_top_size" 
      android:elevation="1dp" 
      android:spinnerMode="dropdown" 
      android:background="@drawable/spinner_style" 
      android:layout_width="match_parent" 
      android:textColor="@color/green_text" 
      android:layout_weight="1" 
      android:layout_height="0dp"/> 


     <TextView 
      android:textSize="@dimen/text_view_size" 
      android:layout_marginTop="@dimen/margin_choose_game_type" 
      android:layout_width="wrap_content" 
      android:layout_weight="0.5" 
      android:layout_height="0dp" 
      android:text="@string/switch_airchiet_xishti"/> 

     <Spinner 
      android:id="@+id/spinner_xishti_id" 
      android:layout_marginTop="@dimen/spinner_margin_top_size" 
      android:elevation="1dp" 
      android:background="@drawable/spinner_style" 
      android:layout_width="match_parent" 
      android:layout_weight="1" 
      android:layout_height="0dp"/> 


     <Switch 
      android:layout_marginTop="@dimen/switch_margin_size" 
      android:id="@+id/wyvilebi_switch_id" 
      android:text="@string/pears" 
      android:textSize="@dimen/switch_text_size" 
      android:textColor="@color/text_color" 
      android:layout_width="match_parent" 
      android:layout_weight="0.5" 
      android:layout_height="0dp"/> 


     <Switch 
      android:layout_marginTop="@dimen/switch_margin_size" 
      android:id="@+id/moshla_switch_id" 
      android:text="@string/moshla_switch_string" 
      android:textSize="@dimen/switch_text_size" 
      android:layout_width="match_parent" 
      android:textColor="@color/text_color" 
      android:layout_weight="0.5" 
      android:layout_height="0dp"/> 



     <Button 
      android:layout_marginTop="@dimen/start_btn_margin_top_size" 
      android:id="@+id/start_game_button_id" 
      android:text="@string/start_game_button" 
      android:layout_marginBottom="@dimen/start_btn_margin_bottom_size" 
      android:textColor="@color/white" 
      android:textSize="@dimen/start_game_btn_txt_size" 
      android:background="@drawable/start_button_style" 
      android:layout_width="match_parent" 
      android:layout_weight="1" 
      android:layout_height="0dp"/> 


    </LinearLayout> 


    </LinearLayout> 

+0

Pourquoi ne pas utiliser un menu contextuel? Recherchez-le et voyez. –

+0

parce que j'ai besoin d'un effet d'animation vers le bas –

+0

Que diriez-vous de 'RelativeLayout' s'aligne au sommet des parents. – NamNH

Répondre

0

J'ai résolu ce

ici est mon xml

................ 
<!-- Toolbar --> 
<include 
    layout="@layout/toolbar" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"/> 

<!-- content--> 

<LinearLayout 
    android:layout_below="@+id/toolbar" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/container"> 

    <!-- menu --> 
    <LinearLayout 
     android:layout_marginTop="@dimen/menu_margin_top" 
     android:visibility="invisible" 
     android:id="@+id/menu_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

    </LinearLayout> 

<!-- main container layout --> 
<LinearLayout 
    android:id="@+id/main_container_id" 
    android:orientation="vertical" 
    android:layout_weight="1" 
    android:layout_width="match_parent" 
    android:layout_height="0dp"> 

    <!-- content container layout--> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_weight="1" 
     android:layout_width="match_parent" 
     android:layout_height="0dp"> 


    </LinearLayout> 


    </LinearLayout> 

</LinearLayout> 

et voici le code java

private boolean isShown = false; 
private void burgerMenuIconClick(){ 
    toolbar.setNavigationOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      if (!isShown) { 
       menuLayout.setVisibility(View.VISIBLE); 
       menuLayout.animate().translationY(menuLayout.getHeight()); 
       isShown = true; 
      } else { 
       menuLayout.animate().translationY(menuLayout.getHeight() * (-1)); 
       isShown = false; 
      } 
     } 
    }); 
}