{"id":13638899,"url":"https://github.com/mzule/FantasySlide","last_synced_at":"2025-04-19T21:35:08.573Z","repository":{"id":76043535,"uuid":"67618712","full_name":"mzule/FantasySlide","owner":"mzule","description":"Another sliding menu base on DrawerLayout","archived":false,"fork":false,"pushed_at":"2017-02-15T11:27:09.000Z","size":4277,"stargazers_count":1425,"open_issues_count":4,"forks_count":221,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-04-12T17:50:00.437Z","etag":null,"topics":["drawerlayout","menubar","sidebar"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mzule.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}},"created_at":"2016-09-07T15:17:04.000Z","updated_at":"2025-04-11T09:40:44.000Z","dependencies_parsed_at":"2024-01-14T11:14:29.894Z","dependency_job_id":null,"html_url":"https://github.com/mzule/FantasySlide","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzule%2FFantasySlide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzule%2FFantasySlide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzule%2FFantasySlide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mzule%2FFantasySlide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mzule","download_url":"https://codeload.github.com/mzule/FantasySlide/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249811137,"owners_count":21328749,"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":["drawerlayout","menubar","sidebar"],"created_at":"2024-08-02T01:00:55.191Z","updated_at":"2025-04-19T21:35:08.538Z","avatar_url":"https://github.com/mzule.png","language":"Java","readme":"# FantasySlide\n\n[![DOWNLOAD](https://api.bintray.com/packages/mzule/maven/fantasy-slide/images/download.svg)](https://bintray.com/mzule/maven/fantasy-slide/_latestVersion)\n[![API](https://img.shields.io/badge/API-15%2B-orange.svg?style=flat)](https://android-arsenal.com/api?level=15)\n\u003ca href=\"http://www.methodscount.com/?lib=com.github.mzule.fantasyslide%3Alibrary%3A1.0.4\"\u003e\u003cimg src=\"https://img.shields.io/badge/Methods and size-core: 142 | deps: 15054 | 24 KB-e91e63.svg\"/\u003e\u003c/a\u003e\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-FantasySlide-green.svg?style=flat)](http://android-arsenal.com/details/1/4309)\n\n一个 DrawerLayout 的扩展,具有帅气的动画与创新的交互。一次手势完成滑出侧边栏与选择菜单。欢迎下载 demo 体验。\n\n\u003chttps://raw.githubusercontent.com/mzule/FantasySlide/master/demo.apk\u003e\n\n## 效果\n\n![](https://raw.githubusercontent.com/mzule/FantasySlide/master/sample.gif)\n\n\n## 使用方法\n\n### 添加依赖\n\n``` groovy\ncompile 'com.github.mzule.fantasyslide:library:1.0.5'\n```\n\n### 调用\n\n调用方法基本与 DrawerLayout 一致. 本项目支持左右 (start left end right) 侧边栏同时定义。\n\n``` xml\n\u003ccom.github.mzule.fantasyslide.FantasyDrawerLayout xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n    android:id=\"@+id/drawerLayout\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\u003e\n\n    \u003cImageView\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        android:scaleType=\"centerCrop\"\n        android:src=\"@drawable/fake\" /\u003e\n\n    \u003ccom.github.mzule.fantasyslide.SideBar\n        android:id=\"@+id/leftSideBar\"\n        android:layout_width=\"200dp\"\n        android:layout_height=\"match_parent\"\n        android:layout_gravity=\"start\"\n        android:background=\"@color/colorPrimary\"\n        app:maxTranslationX=\"66dp\"\u003e\n        \n        \u003c!-- 这里是 SideBar 的子视图--\u003e\n        \n    \u003c/com.github.mzule.fantasyslide.SideBar\u003e\n    \u003c!-- 如果需要的话，可以添加右侧边栏--\u003e\n\u003c/com.github.mzule.fantasyslide.FantasyDrawerLayout\u003e\n\n```\n\n1. 最外层的 FantasyDrawerLayout 的使用与官方的 DrawerLayout 完全一致。\n2. SideBar 用来包装每一个菜单项，SideBar 本质上可以当做一个 vertical 的 LinearLayout 来使用。\n3. 效果图上的文字变色是表示该菜单处于 hover 状态, hover 状态默认会设定 view 的 pressed 状态为 true。可以通过 Listener 来改写, 下文会有详细说明。\n4. 详细参考 \u003chttps://github.com/mzule/FantasySlide/blob/master/app/src/main/res/layout/activity_main.xml\u003e\n\n\n\n## 进阶\n\n### maxTranslationX\n\n通过设置 maxTranslationX 可以设置菜单项动画的最大位移。仅有在采用默认 Transformer 时才有效。\n\n``` xml\n\u003ccom.github.mzule.fantasyslide.SideBar\n\t...\n    app:maxTranslationX=\"88dp\"\u003e\n```\n一般情况下，左边的侧边栏 maxTranslationX 为正数，右边的侧边栏 maxTranslationX 为负数。\n\n\n### Listener\n\n支持设置 Listener 来监听侧边栏菜单的状态。\n\n``` java\nSideBar leftSideBar = (SideBar) findViewById(R.id.leftSideBar);\nleftSideBar.setFantasyListener(new SimpleFantasyListener() {\n    @Override\n    public boolean onHover(@Nullable View view) {\n    \treturn false;\n    }\n\n    @Override\n    public boolean onSelect(View view) {\n        return false;\n    }\n\n    @Override\n    public void onCancel() {\n    }\n});\n```\n\n1. Hover 是指上面效果图中，高亮的状态，此时手指仍在屏幕上 move. 默认的 hover 处理逻辑是设置 view 的 pressed 状态为 true. 重写 onHover(View) 方法返回 true 可以改写默认逻辑。\n2. Select 是指 hover 状态时手指离开屏幕，触发 select 状态。默认的处理逻辑是调用 view 的 onClick 事件。重写 onSelect(View) 方法返回 true 可以改写默认逻辑。\n3. Cancel 是指手指离开屏幕时，没有任何 view 触发 select 状态，则为 cancel，无默认处理逻辑。\n\n### Transformer\n\n项目设计了一个 Transformer 接口，供调用者自定义菜单项的动画效果。使用方法类似于 ViewPager 的 PageTransformer.\n\n``` java\nclass DefaultTransformer implements Transformer {\n    private float maxTranslationX;\n\n    DefaultTransformer(float maxTranslationX) {\n        this.maxTranslationX = maxTranslationX;\n    }\n\n    @Override\n    public void apply(ViewGroup sideBar, View itemView, float touchY, float slideOffset, boolean isLeft) {\n        float translationX;\n        int centerY = itemView.getTop() + itemView.getHeight() / 2;\n        float distance = Math.abs(touchY - centerY);\n        float scale = distance / sideBar.getHeight() * 3; // 距离中心点距离与 sideBar 的 1/3 对比\n        if (isLeft) {\n            translationX = Math.max(0, maxTranslationX - scale * maxTranslationX);\n        } else {\n            translationX = Math.min(0, maxTranslationX - scale * maxTranslationX);\n        }\n        itemView.setTranslationX(translationX * slideOffset);\n    }\n}\n```\n\n## 感谢\n\n动画效果参考自 dribbble. \u003chttps://dribbble.com/shots/2269140-Force-Touch-Slide-Menu\u003e 在此感谢。\n\n另外，demo 里面 MainActivity 的右边栏实现了类似原作的菜单动画效果。具体可以参考相关代码。\n\n## 许可\n\nApache License  2.0\n\n## 联系我\n\n任何相关问题都可以通过以下方式联系我。\n\n1. 提 issue\n1. 新浪微博 http://weibo.com/mzule\n1. 个人博客 https://mzule.github.io/\n1. 邮件 \"mzule\".concat(\"4j\").concat(\"@\").concat(\"gmail.com\")\n","funding_links":[],"categories":["抽屉菜单"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmzule%2FFantasySlide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmzule%2FFantasySlide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmzule%2FFantasySlide/lists"}