简体   繁体   中英

Navigation Drawer not Starting from top position

I am working with navigation drawer , There are 12 items and it is working well .when I open navigation drawer then it is shows from 3rd item on top my profile picture is on the top which is not showing. I want to start it from the top. where is my profile picture. I have used `mDrawerList.setSelection(0); but it is starting with 3rd item and suddenly going to top . please help me to solve the problem.

My XML Code below.

<FrameLayout
    android:id="@+id/toolbarLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:fitsSystemWindows="true"
        android:orientation="vertical">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/color_primary_green_header"
            android:gravity="center_vertical"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/ThemeOverlay.AppCompat.Dark" />

        <!-- The main content view -->
        <LinearLayout
            android:id="@+id/mainContent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#ffffff"
            android:orientation="vertical" />
    </LinearLayout>
</FrameLayout>


<ListView
    android:id="@+id/nav_list"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_below="@+id/profileBox"
    android:layout_gravity="start"
    android:background="@color/list_background"
    android:choiceMode="singleChoice"
    android:divider="@null" />

  public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            mDrawerList.setSelection(0);
            invalidateOptionsMenu();
            listAdapter.notifyDataSetChanged();
 public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            // Log.d(TAG, "onDrawerClosed: " + getTitle());
            Log.e("TKB", " Nav Drawer is closed");
            mDrawerList.setSelection(0);
            //invalidateOptionsMenu();
        }
    };

您可以使用smoothScroll选择导航抽屉的索引。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM