Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 导航抽屉滑动缓慢_Android_Android Animation_Navigation Drawer_Grid Layout - Fatal编程技术网

Android 导航抽屉滑动缓慢

Android 导航抽屉滑动缓慢,android,android-animation,navigation-drawer,grid-layout,Android,Android Animation,Navigation Drawer,Grid Layout,在我的Android程序中,我还没有设置到物品抽屉中物品的链接。当我通过使活动为空来滑动它们时,它会平滑地滑动,但当我向活动和幻灯片添加网格布局(只有一个大小为100KB的图像)时,滑动会滞后。有人能帮我吗 DrawerLayout mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer); ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this,mDr

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

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" />

我的网格单一布局:

<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();

        }
    });
GridView网格;
CustomGrid adapter=新的CustomGrid(MainActivity.this、web、imageId);
grid=(GridView)findviewbyd(R.id.grid);
设置适配器(适配器);
grid.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
Toast.makeText(MainActivity.this,“您在“+web[+position],Toast.LENGTH_SHORT.show]上单击过它”);
}
});

能否显示代码,在哪里组织网格布局并将图像加载到其中?谢谢。@MichaelSpitsin添加了代码。您是否在UI线程中添加和加载图像?我在drawable中添加了图像,并使用Java类中的适配器将其添加到布局中。您是否可以显示代码,从何处组织网格布局并将图像加载到其中?谢谢。@MichaelSpitsin添加了代码您是否在UI线程中添加和加载图像?我在drawable中添加了图像,并使用Java类中的适配器将其添加到布局中。