Transition in navigation drawer android

后端 未结 2 1240
你的背包
你的背包 2021-01-01 00:46

Anyone having idea that how to achieve this type of transition. When we open Navagation drawer full screen is getting animation like this. I also looked at resi

相关标签:
2条回答
  • 2021-01-01 01:10

    Finally I got my answer through this link for original post. Please have a look here

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="test.pyramidions.com.dynamicview2.MainActivity"
    tools:openDrawer="start">
    
    
    <RelativeLayout
        android:id="@+id/holder"
        android:layout_width="match_parent"
        android:background="@drawable/shadow"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
    
        <LinearLayout
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:background="@color/colorAccent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
            <include
                android:id="@+id/toolbar"
                layout="@layout/toolbar" />
    
    
            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1" />
    
        </LinearLayout>
    </RelativeLayout>
    
    
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/drawer_menu" />
    
     </android.support.v4.widget.DrawerLayout>
    

    and for MainActivity.java please have a look below

            public class MainActivity extends AppCompatActivity {
    public TabsPagerAdapter tabsPagerAdapter;
    public static ViewPager pager;
    int Numboftabs = 2;
    Toolbar toolbar;
    public NavigationView navigationView;
    public DrawerLayout drawer;
    View holderView, contentView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        navigationView = (NavigationView) findViewById(R.id.nav_view);
        holderView = findViewById(R.id.holder);
        contentView = findViewById(R.id.content);
        tabsPagerAdapter = new TabsPagerAdapter(getSupportFragmentManager(), Numboftabs);
        pager = (ViewPager) findViewById(R.id.pager);
        pager.setAdapter(tabsPagerAdapter);
        toolbar.setNavigationIcon(new DrawerArrowDrawable(this));
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
                                                 @Override
                                                 public void onClick(View v) {
                                                     if (drawer.isDrawerOpen(navigationView)) {
                                                         drawer.closeDrawer(navigationView);
                                                     } else {
                                                         drawer.openDrawer(navigationView);
                                                     }
                                                 }
                                             }
        );
    
    
        drawer.setScrimColor(Color.TRANSPARENT);
        drawer.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
                                     @Override
                                     public void onDrawerSlide(View drawer, float slideOffset) {
    
    
                                         contentView.setX(navigationView.getWidth() * slideOffset);
                                         RelativeLayout.LayoutParams lp =
                                                 (RelativeLayout.LayoutParams) contentView.getLayoutParams();
                                         lp.height = drawer.getHeight() -
                                                 (int) (drawer.getHeight() * slideOffset * 0.3f);
                                         lp.topMargin = (drawer.getHeight() - lp.height) / 2;
                                         contentView.setLayoutParams(lp);
                                     }
    
                                     @Override
                                     public void onDrawerClosed(View drawerView) {
                                     }
                                 }
        );
    
    }
    
    0 讨论(0)
  • 2021-01-01 01:23

    Drawer behavior is a library use Android DrawerLayout Support library as Parent Class [Easy to migrate], that provide an extra behavior on drawer, such as, move view or scaling view's height while drawer on slide.

    If current project use Android DrawerLayout Support library and kinda boring with the effect. Then, just change the layout code and calling necessary method for animation/effect.

    Check out github code

    Gradle

    dependencies {
       implementation 'com.infideap.drawerbehavior:drawer-behavior:0.1.5'
    }
    

    if the gradle unable to sync, you may include this line in project level gradle,

    repositories {
     maven{
       url "https://dl.bintray.com/infideap2/Drawer-Behavior"
     }
    }
    
    0 讨论(0)
提交回复
热议问题