2017-08-02 3 views
0

im Anfänger von Android. Ich entwerfe eine Navigationsschublade wie folgt: enter image description hereVon links nach rechts Menüelemente Android in NavigationView

wie Sie sehen, sind alle Elemente im Menü auf der rechten Seite außer "SubHeader".

Wie kann ich "SubHeader" Element auf der rechten Seite dieses Menüs verschieben? Ich benutze alle Eigenschaften wie Schwerkraft, Layout Schwerkraft, layoutDirection zum SubHeaderItem, aber es funktioniert nicht.

mein Code

<android.support.design.widget.NavigationView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:id="@+id/navigation_view" 
     android:layout_gravity="end" 
     android:fitsSystemWindows="true" 
     android:layoutDirection="rtl" 
     app:headerLayout="@layout/navigation_header" 
     app:menu="@menu/navigation_menu" 
     /> 

mein Menü-Code ist:

<menu xmlns:android="http://schemas.android.com/apk/res/android" > 
    <group android:checkableBehavior="single"> 
     <item 
      android:title="inbox" 
      android:id="@+id/inbox_id" 
      android:icon="@drawable/inbox" /> 
    </group> 
    <item android:title="SubHeader"> 

     <menu> 
      <item 
       android:title="all main" 
       android:id="@+id/all_mail" 
       android:icon="@drawable/allmail" /> 
     </menu> 
    </item> 

</menu> 
+0

hinzufügen Schwerkraft = "right" ur Menüpunkt. – james

+0

@james danke, aber ich füge es hinzu und funktioniert nicht –

Antwort

2

Versuchen Sie, diese Attribute zu NavigationView in Ihrer Layoutdatei hinzuzufügen.

android:layoutDirection="rtl" 
android:textDirection="rtl" 

Wenn nicht anders. Sie sollten benutzerdefiniertes Layout

Beispiel verwenden:

<android.support.design.widget.NavigationView 
    android:layoutDirection="rtl" 
    android:id="@+id/navigation_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="right" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header_main" 
    app:menu="@menu/activity_main_drawer> 
<LinearLayout> 
// code xml here 
</LinearLayout> 
<android.support.design.widget.NavigationView/> 
+0

danke so viel .. ich habe textDirection Attribut hinzugefügt und es funktioniert .. –

+0

glücklich !!!!!!!!!! –

0

versuchen dies Ihr Menü Schwerkraft = "right" des Menüpunktes

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:gravity="end" 
android:layoutDirection="rtl" 
android:layout_gravity="end"> 

<group android:checkableBehavior="single" 
    android:layout_gravity="end" 
    android:gravity="end"> 

    <item 
     android:id="@+id/nav_1" 
     android:icon="@drawable/abc" 
     android:gravity="end" 
     android:layout_gravity="end" 
     android:title="menu title"/> 
    </group> 
</menu> 

und machen Sie Ihre Navigationsansicht so

<android.support.design.widget.NavigationView 
     android:layoutDirection="rtl" 
     android:id="@+id/navigation_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="right" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header_main" 
     app:menu="@menu/activity_main_drawer" /> 
+0

danke, aber es funktioniert nicht –

+0

@hosseinderakhshan überprüfen aktualisiert ans –

+0

danke aber immer noch nicht arbeiten .. –

Verwandte Themen