自定义动画用于抽屉导航栏的打开和关闭

11

让我们做些有挑战性的事情。我看过这个导航抽屉的动画:enter image description here

我想按照原样实现它,因为它是一个很棒的效果。我尝试通过创建自定义视图并在触摸时获取至少50%相似的效果。 我想从我的自定义视图的ondraw()和ontouch()方法中实现到导航视图。如何做到呢?有人有任何线索吗?有人能给出类似的参考链接吗。

我已经尝试过:

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

    }

}

onDraw方法为什么没有被调用?

从主活动中,我创建了一个以上类的对象,并像下面这样调用start方法:

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

这只是最初的东西,我还想要实现以下内容:


大家好,有没有人知道如何实现在列表视图项目上点击并打开一个详细页面动画,就像上面的图片一样?感谢您的帮助。提前致谢。 - KeTaN
2个回答

5

最终,在找了很多后,我找到了一个相关的库,这里是它的链接。我不知道为什么这么难找到,或者只是我的糟糕一周,无论如何,对于那些希望使用它的人,你们可以在这里找到这个库。此外,如果需要,我还会提供实现:

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


}

现在NavigationView被视为一个片段,在这里的片段代码如下:

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

基本上就是这样了。您可以感谢这个人的出色工作。


无法启动...显示这个错误。 java.lang.RuntimeException: 无法启动活动 ComponentInfo{com.mxn.soul.flowingdrawer/com.mxn.soul.flowingdrawer.MainActivity}: java.lang.IllegalArgumentException: 目标不能为空。 - Debasish Ghosh
由于:java.lang.IllegalArgumentException: 目标不能为空。 在com.squareup.picasso.RequestCreator.into(RequestCreator.java:607)处 在com.squareup.picasso.RequestCreator.into(RequestCreator.java:590)处 在com.mxn.soul.flowingdrawer.MenuListFragment.setupHeader(MenuListFragment.java:58)处 在com.mxn.soul.flowingdrawer.MenuListFragment.onCreateView(MenuListFragment.java:45)处。 - Debasish Ghosh

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接