Custom Animation for navigation drawer open and close

拥有回忆 提交于 2019-12-31 13:43:33

问题


Lets do something challanging. I have seen this animation for navigation Drawer :

and I would like to implement this as it is a great effect. I tried to get the effect by creating a custom view and on touch i am getting at least 50% similar effect. i would like to implement my ondraw() and ontouch() methods from my custom view to navigation view. How is that done? Any one have any clue? Can anyone give any link which has simlar stuff.

I have tried this :

public class CustomNavigation extends DrawerLayout {

    public CustomNavigation(Context context) {
        super(context);
    }

    public CustomNavigation(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomNavigation(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
//        invalidate();
    }
    public void start()
    {
        this.invalidate();
        Log.d("Parth", "start");
    }

    @Override
    public void onDraw(Canvas c) {
        Log.d("Parth", "ondraw");
//        super.onDraw(c);

    }

}

The on draw method isn't called. why is that so?

from the main activity i make an object of the class above and call the start method like this :

CustomNavigation drawer = (CustomNavigation) findViewById(R.id.drawer_layout);
drawer.start();

and this is just the initial stuff, i also want to implement these :

  • https://mir-s3-cdn-cf.behance.net/project_modules/disp/1637a925685965.56349328a6a5e.gif

  • https://mir-s3-cdn-cf.behance.net/project_modules/disp/092d8f25685965.5634935a53dde.gif


回答1:


So finally after finding so much i found a library for this, and here is the link to it. I don't know why it was so hard to find. Or it was just my bad week anyways for those who wish to use it you'll can find the library here. and more over i will also give the implementation if you need it :

main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<com.mxn.soul.flowingdrawer_core.LeftDrawerLayout
    android:id="@+id/id_drawerlayout"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"

    >

    <!--content-->
    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    </android.support.design.widget.CoordinatorLayout>

    <!--menu-->
    <RelativeLayout
        android:layout_width="280dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:clipChildren="false"
        >
        <com.mxn.soul.flowingdrawer_core.FlowingView
            android:paddingRight="35dp"
            android:id="@+id/sv"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
        <FrameLayout
            android:id="@+id/id_container_menu"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_marginRight="25dp"

            />
    </RelativeLayout>

</com.mxn.soul.flowingdrawer_core.LeftDrawerLayout>

Main_activity.java

public class MainActivity extends AppCompatActivity{

    private LeftDrawerLayout mLeftDrawerLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mLeftDrawerLayout = (LeftDrawerLayout) findViewById(R.id.id_drawerlayout);

        FragmentManager fm = getSupportFragmentManager();
        MyMenuFragment mMenuFragment = (MyMenuFragment) fm.findFragmentById(R.id.id_container_menu);
        FlowingView mFlowingView = (FlowingView) findViewById(R.id.sv);
        if (mMenuFragment == null) {
            fm.beginTransaction().add(R.id.id_container_menu, mMenuFragment = new MyMenuFragment()).commit();
        }
        mLeftDrawerLayout.setFluidView(mFlowingView);
        mLeftDrawerLayout.setMenuFragment(mMenuFragment);
    }


}

now the navigationview is considered as a fragment here so code for the fragment is here :

public class MyMenuFragment extends MenuFragment{
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment,container,false);

        return setupReveal(v);
    }
}

So this is pretty much it. You can thank this person for the wonderful work.




回答2:


Flabby animation

You can take help from this LINK

A video example of this library is on this youtube video.

The demo app can be found on the play store.



来源:https://stackoverflow.com/questions/35448807/custom-animation-for-navigation-drawer-open-and-close

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!