{"id":21888557,"url":"https://github.com/pythoncat1024/drawermenu","last_synced_at":"2025-08-22T07:42:00.315Z","repository":{"id":107255398,"uuid":"89899878","full_name":"pythoncat1024/DrawerMenu","owner":"pythoncat1024","description":null,"archived":false,"fork":false,"pushed_at":"2017-05-01T06:12:24.000Z","size":631,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-26T20:32:18.253Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pythoncat1024.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-01T05:29:38.000Z","updated_at":"2017-05-01T05:29:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"66ce388e-6613-4b4a-9657-e485d8af5187","html_url":"https://github.com/pythoncat1024/DrawerMenu","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythoncat1024%2FDrawerMenu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythoncat1024%2FDrawerMenu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythoncat1024%2FDrawerMenu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythoncat1024%2FDrawerMenu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pythoncat1024","download_url":"https://codeload.github.com/pythoncat1024/DrawerMenu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244895512,"owners_count":20527902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-28T11:15:57.287Z","updated_at":"2025-03-22T02:23:58.784Z","avatar_url":"https://github.com/pythoncat1024.png","language":"Java","readme":"# DrawerMenu\n\n手写一个侧滑菜单是一种怎样的体验？\n\n* android app 中有很多侧滑菜单的需求，于是谷歌推出了`DrawerLayout`控件。基本满足了用户的侧滑菜单需求。\n* 但是，总有一些时候，需要去使用自定义的控件。\n* 这个`DrawerMenu`就是在这种场景下出现的。首先，可以肯定的是，肯定没有原生的`DrawerLayout`好。但是，这个不重要的，重要的是，理清楚其中的逻辑。\n\n\t* 为什么可以侧滑？\n\t* 怎么做才能侧滑？\n\t* 如果实现侧滑，会不会影响菜单栏的点击事件？\n\t* 实现侧滑，有哪些注意事项？\n* 我已经在网上看到过几十个人实现的侧滑菜单的讲解。优劣并不好区分。因为这个不重要。因为再好，也不会比原生的更好了。但是，造轮子的意义就在于，弄清楚其中的机理。\n* 其实很多技术点，就是一张纸：捅破了，就明白了；不捅破，死也不能明白。\n* 这篇侧滑菜单，就是为了捅捅。\n\n**How to**\n\u003e To get a Git project into your build:\n\n* Step 1. Add the JitPack repository to your build file\n\u003e Add it in your root build.gradle at the end of repositories:\n\n\t```gradle\n\tallprojects {\n\t\trepositories {\n\t\t\t...\n\t\t\tmaven { url 'https://jitpack.io' }\n\t\t}\n\t}\n\t```\n* Step 2. Add the dependency\n\n\t```gradle\n\t\tdependencies {\n\t        compile 'com.github.pythoncat1024:DrawerMenu:1.0.0'\n\t\t}\n\t```\n* Step 3. edit you Activity's xml\n\t```xml\n\t   \u003ccom.python.cat.drawerlayout.DrawerMenu\n        android:id=\"@+id/dm_layout\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\u003e\n\n\t        \u003cinclude layout=\"@layout/left_menu_layout\" /\u003e\n\t\n\t        \u003cinclude layout=\"@layout/main_layout\" /\u003e\n\t    \u003c/com.python.cat.drawerlayout.DrawerMenu\u003e\n\t```\n* Step 4. edit you Activity （*如果只是要看侧滑效果，可以没有这一步*）\n```java\nfinal DrawerMenu dm = (DrawerMenu) findViewById(R.id.dm_layout);\n        findViewById(R.id.main_tv).setOnClickListener(new View.OnClickListener() {\n            @Override\n            public void onClick(View v) {\n                dm.changeState();\n            }\n        });\n        vp = (ViewPager) findViewById(R.id.main_view_pager);\n        View v1 = LayoutInflater.from(this).inflate(R.layout.vp_layout_01, null);\n        View v2 = LayoutInflater.from(this).inflate(R.layout.vp_layout_02, null);\n        View v3 = LayoutInflater.from(this).inflate(R.layout.vp_layout_03, null);\n        View v4 = LayoutInflater.from(this).inflate(R.layout.vp_layout_04, null);\n        final ArrayList\u003cView\u003e viewList = new ArrayList\u003c\u003e();\n        viewList.add(v1);\n        viewList.add(v2);\n        viewList.add(v3);\n        viewList.add(v4);\n        vp.setAdapter(new PagerAdapter() {\n            @Override\n            public int getCount() {\n                return viewList.size();\n            }\n\n            @Override\n            public boolean isViewFromObject(View view, Object object) {\n                return view == object;\n            }\n\n            @Override\n            public void destroyItem(ViewGroup container, int position,\n                                    Object object) {\n                container.removeView(viewList.get(position));\n            }\n\n            @Override\n            public Object instantiateItem(ViewGroup container, int position) {\n                container.addView(viewList.get(position));\n                return viewList.get(position);\n            }\n        });\n    }\n\n    public void leftMenuClick(View view) {\n        String text = ((TextView) view).getText().toString();\n        LogUtils.e(\"item = \" + view.getId() + \" , text = \" + text);\n        Toast.makeText(getApplicationContext(),\n                text,\n                Toast.LENGTH_SHORT)\n                .show();\n    }\n```\n\n具体实现：参考源码  [核心逻辑](https://github.com/pythoncat1024/DrawerMenu/blob/master/drawerlayout/src/main/java/com/python/cat/drawerlayout/DrawerMenu.java)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythoncat1024%2Fdrawermenu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpythoncat1024%2Fdrawermenu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythoncat1024%2Fdrawermenu/lists"}