用于导航抽屉打开和关闭的自定义动画 [英] Custom Animation for navigation drawer open and close

查看:84
本文介绍了用于导航抽屉打开和关闭的自定义动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们做些具有挑战性的事情.我看过这个用于导航抽屉的动画:

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

,我想实现它,因为它效果很好.我试图通过创建自定义视图来获得效果,并且在触摸时我至少获得了50%的相似效果.我想从我的自定义视图到导航视图实现我的ondraw()和ontouch()方法.这是怎么做的?任何人有任何线索吗?任何人都可以提供包含类似内容的任何链接.

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.

我已经尝试过:

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

    }

}

不调用on draw方法.为什么会这样?

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

在主要活动中,我创建了上述类的对象,并像这样调用start方法:

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/092d8f25685965.5634935a53dde.gif

推荐答案

因此,终于在找到了很多东西之后,我为此找到了一个库,这是

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

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

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.

这篇关于用于导航抽屉打开和关闭的自定义动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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