【问题标题】:Custom Animation for navigation drawer open and close导航抽屉打开和关闭的自定义动画
【发布时间】:2016-02-17 05:44:14
【问题描述】:

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

我想实现它,因为它的效果很好。我试图通过创建自定义视图来获得效果,并且在触摸时我得到了至少 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);

    }

}

未调用 on draw 方法。为什么会这样?

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

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

这只是最初的东西,我也想实现这些:

【问题讨论】:

  • 您好,任何人都知道如何实现单击列表视图项并打开如上图所示的详细页面动画,帮助感谢提前感谢

标签: android navigation-drawer material-design


【解决方案1】:

所以终于在找到了这么多之后我找到了一个库,这里是link。我不知道为什么这么难找。或者对于那些希望使用它的人来说,这只是我糟糕的一周,你可以在这里找到图书馆。如果你需要的话,我也会给出实现:

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


}

现在导航视图在这里被视为一个片段,因此片段的代码在这里:

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

差不多就是这样。您可以感谢this person 的出色工作。

【讨论】:

  • 未启动...显示此错误。 java.lang.RuntimeException:无法启动活动 ComponentInfo{com.mxn.soul.flowingdrawer/com.mxn.soul.flowingdrawer.MainActivity}:java.lang.IllegalArgumentException:目标不能为空。
  • 引起: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)
【解决方案2】:

松弛动画

你可以从这个LINK获得帮助

此库的视频示例位于 youtube video.

demo app 可以在 Play 商店中找到。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-08
    • 2016-05-05
    • 2020-04-10
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多