2016-06-27 21 views
5

Tôi có Ngăn điều hướng mở từ phải sang trái, mọi thứ hoạt động tốt và biểu tượng bánh hamburger đang hoạt động tốt và ở góc bên phải nhưng biểu tượng menu ở bên trái các mục menu.Hiển thị biểu tượng menu ngăn kéo ở bên phải các mục menu

Cách di chuyển chúng sang bên phải của các mục menu?

Xin xem màn hình bắn

enter image description here

Đây là menu.xml tôi

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android"> 
    <group android:checkableBehavior="none"> 
     <item 
      android:id="@+id/nav_home" 
      android:icon="@drawable/ic_navigation_home" 
      android:title="@string/nav_menu_home" /> 
     <item 
      android:id="@+id/nav_profile" 
      android:icon="@drawable/ic_menu_profile" 
      android:title="@string/nav_profile" /> 
     <item 
      android:id="@+id/nav_help" 
      android:icon="@drawable/ic_navigation_help" 
      android:title="@string/nav_help" /> 
     <item 
      android:id="@+id/nav_manage" 
      android:icon="@drawable/ic_menu_manage" 
      android:title="@string/nav_manage" /> 
     <item 
      android:id="@+id/nav_logout" 
      android:icon="@drawable/ic_logout" 
      android:title="@string/nav_logout" /> 
    </group> 
    <item android:title="@string/nav_communicate"> 
     <menu> 
      <item 
       android:id="@+id/nav_facebook" 
       android:icon="@drawable/ic_facebookx" 
       android:title="@string/nav_face_page" /> 
      <item 
       android:id="@+id/nav_send" 
       android:icon="@drawable/ic_menu_send" 
       android:title="@string/nav_contact" /> 
     </menu> 
    </item> 
</menu> 

và đây là cách bố trí của tôi

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 
    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 
</android.support.design.widget.AppBarLayout> 
<android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 
    <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header_main" 
     app:menu="@menu/activity_main_drawer" /> 
</android.support.v4.widget.DrawerLayout> 
</LinearLayout> 

tôi đã tìm kiếm rất nhiều nhưng didn' t tìm thấy bất cứ điều gì liên quan đến vấn đề này.

Xin cảm ơn trước.

+0

Cần thêm phân đoạn và thử thực hiện với reclyerview –

+0

@WaqarYounis Cảm ơn bạn đã gợi ý :) – Mohammad

Trả lời

3

Nếu bạn muốn sử dụng NavigationView để xử lý DrawerLayout cách duy nhất mà tồn tại (hiện tại) là để làm cho bạn NavigationView phải sang trái bằng đoạn mã sau:

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) //call this before super.onCreate 
private void forceRtlIfSupported() { 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { 
     getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL); 
    } 
} 

và thiết lập RTL cờ trong AndroidManifiest.xml

android:supportsRtl="true" 

không may theo cách này chỉ được hỗ trợ cho API 16 trở lên. Nhưng bạn cũng có thể thực hiện DrawerLayout với ListView và sau đó bạn có thể làm bất cứ điều gì bạn muốn. bạn có thể tìm thấy hướng dẫn về phương pháp này here.

+1

Cảm ơn bạn rất nhiều. Tôi sẽ cung cấp cho nó một thử và lấy lại cho bạn :) – Mohammad

Các vấn đề liên quan