DrawerLayout打开样的步骤在第一时间 [英] DrawerLayout opens kind of in steps the first time

查看:407
本文介绍了DrawerLayout打开样的步骤在第一时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,当我刷它的第一次,它是在步骤(如延迟或类似的东西)来了一个DrawerLayout,但之后它移动的罚款。我不知道是什么code后,因为正如我所说的它的正常工作,只有当我打开它的第一次,它不顺利打开。

I have a DrawerLayout which the first time when I swipe it, it is coming in steps(like lag or something similar), but after that it moves fine. I don't know what code to post, because as I said it's working fine, only the first time when I open it, it doesn't open smoothly.

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/DrawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="7dp">

    <RelativeLayout 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"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="name.company.newapp.HomeScreen"
        tools:showIn="@layout/activity_home_screen">

        <FrameLayout
            android:id="@+id/your_placeholder"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    </RelativeLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/RecyclerView"
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"

        android:background="#ffffff"
        android:scrollbars="vertical">

    </android.support.v7.widget.RecyclerView>

</android.support.v4.widget.DrawerLayout>

onCreate方法

onCreate method

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_screen);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
 mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View

        LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
        mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);


        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

        mAdapter = new MyDrawerAdapter(TITLES,ICONS,NAME,EMAIL,PROFILE,this);

        mRecyclerView.setAdapter(mAdapter);                              // Setting the adapter to RecyclerView

        mRecyclerView.setHasFixedSize(true);                            // Letting the system know that the list objects are of fixed size

final GestureDetector mGestureDetector = new GestureDetector(HomeScreen.this, new GestureDetector.SimpleOnGestureListener() {

            @Override public boolean onSingleTapUp(MotionEvent e) {
                return true;
            }

        });


        mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
            @Override
            public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
                View child = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY());


                if (child != null && mGestureDetector.onTouchEvent(motionEvent)) {

                    switch(recyclerView.getChildAdapterPosition(child)){
                        case 1:setFragment(new PreferencesFragment());
                            break;
                        default:
                            Toast.makeText(HomeScreen.this, "The Item Clicked is: " + recyclerView.getChildAdapterPosition(child), Toast.LENGTH_SHORT).show();
                    }
                    Drawer.closeDrawers();

                    return true;

                }

                return false;
            }

            @Override
            public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {

            }

            @Override
            public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

            }
        });


        Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout);        // Drawer object Assigned to the view
        mDrawerToggle = new ActionBarDrawerToggle(this,Drawer,toolbar,R.string.navigation_drawer_open,R.string.navigation_drawer_close){

            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                // code here will execute once the drawer is opened( As I dont want anything happened whe drawer is
                // open I am not going to put anything here)
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
                // Code here will execute once drawer is closed
            }



        }; // Drawer Toggle Object Made
        Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle
        mDrawerToggle.syncState();               // Finally we set the drawer toggle sync State

}

编辑:我可能已经找到了解决办法在这里<一个href=\"http://stackoverflow.com/questions/17896052/why-does-drawerlayout-sometimes-glitch-upon-opening\">Why不DrawerLayout在打开有时故障?,但我不知道如何实现它在我的code。

I might have found a solution here Why does DrawerLayout sometimes glitch upon opening? , but I don't know how to implement it in my code.

推荐答案

也许你的问题也是由于图像在导航视图的标题的大小。

Maybe your problem is also due to the size of the image in the header of the Navigation View.

看看这个:
<一href=\"http://stackoverflow.com/questions/31148445/navigationview-slow-to-open-skipping-frames-android-design-lib\">NavigationView慢开/跳帧(Android设计库)

这篇关于DrawerLayout打开样的步骤在第一时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆