导航抽屉滑动缓慢

时间:2016-08-10 05:30:38

标签: android android-animation navigation-drawer grid-layout

在我的Android程序中,我还没有设置Item抽屉项目的链接。当我通过使活动为空来滑动它们时,它会平滑地滑动,但是当我向活动和幻灯片添加网格布局(只有一个大小为100 KB的图像)时,滑动滞后。任何人都可以帮助我吗?

DrawerLayout mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer);
    ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout,toolbar,R.string.app_name,R.string.app_name) {
        private Runnable runnable;
        Intent mPendingDrawerIntent;
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }



        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }


        @Override
        public void onDrawerStateChanged(int newState) {
            super.onDrawerStateChanged(newState);
            if (runnable!=null && newState==DrawerLayout.STATE_IDLE) {
                runnable.run();
                runnable=null;
            }
        }

        public void runWhenIdle(Runnable runnable) {
            this.runnable=runnable;
        }

    };
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();

我的主要布局:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<LinearLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical"
    >
    <include
        layout="@layout/tool_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
    />
    <FrameLayout
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <GridView
            android:numColumns="auto_fit"
            android:gravity="center"
            android:columnWidth="100dp"
            android:stretchMode="columnWidth"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/grid"
            />

    </FrameLayout>

</LinearLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:layout_gravity="start"
    app:headerLayout="@layout/header"
    app:menu="@menu/drawer"
    />

<!--<android.support.design.widget.CoordinatorLayout
   android:id="@+id/main_content"
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   android:layout_width="match_parent"
   android:layout_height="match_parent">

   <android.support.design.widget.FloatingActionButton
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_gravity="bottom|right"
       android:id="@+id/fab"
       android:layout_margin="18dp"
       android:src="@drawable/ic_publish_white_24dp"
       app:layout_anchorGravity="bottom|right|end" />

- &GT;

我的网格单一布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" >

<ImageView
    android:id="@+id/grid_image"
    android:layout_width="100dp"
    android:layout_height="150dp"
    android:padding="0.5dp"
    android:scaleType="centerCrop"
    android:cropToPadding="true"
    android:background="@drawable/border_image"
    >
</ImageView>

班级

中的网格声明
GridView grid;
    CustomGrid adapter = new CustomGrid(MainActivity.this, web, imageId);
    grid=(GridView)findViewById(R.id.grid);
    grid.setAdapter(adapter);
    grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {
            Toast.makeText(MainActivity.this, "You Clicked at " + web[+position], Toast.LENGTH_SHORT).show();

        }
    });

0 个答案:

没有答案