Convert Figma logo to code with AI

mzule logoFantasySlide

Another sliding menu base on DrawerLayout

1,428
224
1,428
4

Top Related Projects

Side menu with some categories to choose.

DrawerLayout-like ViewGroup, where a "drawer" is hidden under the content view, which can be shifted to make the drawer visible.

The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.

An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!

:octocat: 📃 FoldingCell is a material design expanding content cell inspired by folding paper material made by @Ramotion

You can easily add awesome animated context menu to your app.

Quick Overview

FantasySlide is an Android library that provides a customizable sliding drawer menu with a fantasy-style animation. It allows developers to create a unique and visually appealing navigation drawer for their Android applications, enhancing the user experience with smooth transitions and eye-catching effects.

Pros

  • Unique and visually appealing sliding animation
  • Highly customizable, allowing developers to adjust various aspects of the menu
  • Easy to integrate into existing Android projects
  • Supports both left and right sliding directions

Cons

  • Limited documentation and examples
  • Not actively maintained (last update was in 2017)
  • May not be compatible with the latest Android versions or development practices
  • Potential performance impact on older devices due to complex animations

Code Examples

  1. Basic implementation of FantasySlide:
FantasyDrawerLayout fantasyDrawerLayout = findViewById(R.id.fantasyDrawerLayout);
fantasyDrawerLayout.setMenuFragment(new MenuFragment());
  1. Customizing the sliding effect:
fantasyDrawerLayout.setTouchMode(FantasyDrawerLayout.TOUCH_MODE_FULLSCREEN);
fantasyDrawerLayout.setAnimationDuration(500);
fantasyDrawerLayout.setCloseRatio(0.5f);
  1. Adding a listener for drawer events:
fantasyDrawerLayout.addOnDrawerListener(new FantasyDrawerLayout.SimpleOnDrawerListener() {
    @Override
    public void onDrawerOpened(View drawerView) {
        // Handle drawer opened event
    }

    @Override
    public void onDrawerClosed(View drawerView) {
        // Handle drawer closed event
    }
});

Getting Started

To use FantasySlide in your Android project, follow these steps:

  1. Add the JitPack repository to your project's build.gradle file:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the dependency to your app's build.gradle file:
dependencies {
    implementation 'com.github.mzule:FantasySlide:1.0.5'
}
  1. In your layout XML, use the FantasyDrawerLayout as the root view:
<com.mzule.fantasyslide.FantasyDrawerLayout
    android:id="@+id/fantasyDrawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Your main content -->
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- Add your main content here -->
    </FrameLayout>

    <!-- Your menu content -->
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start">
        <!-- Add your menu content here -->
    </FrameLayout>

</com.mzule.fantasyslide.FantasyDrawerLayout>
  1. In your activity or fragment, initialize and customize the FantasyDrawerLayout as needed using the code examples provided above.

Competitor Comparisons

Side menu with some categories to choose.

Pros of Side-Menu.Android

  • More polished and visually appealing animations
  • Better documentation and examples
  • Higher number of stars and forks, indicating wider adoption

Cons of Side-Menu.Android

  • Less customizable compared to FantasySlide
  • Limited to side menu functionality, while FantasySlide offers more versatile sliding options
  • Slightly more complex implementation

Code Comparison

FantasySlide implementation:

FantasyDrawerLayout fantasyDrawerLayout = findViewById(R.id.fantasyDrawerLayout);
fantasyDrawerLayout.setTouchMode(FantasyDrawerLayout.TOUCH_MODE_FULLSCREEN);
fantasyDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

Side-Menu.Android implementation:

ResideMenu resideMenu = new ResideMenu(this);
resideMenu.setBackground(R.drawable.menu_background);
resideMenu.attachToActivity(this);
resideMenu.setMenuListener(menuListener);

Both libraries offer easy-to-implement sliding menu solutions for Android applications. FantasySlide provides more flexibility in terms of customization and sliding options, while Side-Menu.Android focuses on delivering a polished, visually appealing side menu with smoother animations. The choice between the two depends on the specific requirements of your project and the desired level of customization.

DrawerLayout-like ViewGroup, where a "drawer" is hidden under the content view, which can be shifted to make the drawer visible.

Pros of SlidingRootNav

  • More customizable with various animation styles and menu layouts
  • Better support for Material Design guidelines
  • Active development and maintenance

Cons of SlidingRootNav

  • Slightly more complex implementation
  • Requires more setup code
  • May have a steeper learning curve for beginners

Code Comparison

FantasySlide:

FantasyDrawerLayout drawer = (FantasyDrawerLayout) findViewById(R.id.drawer);
drawer.setMenuFragment(new MenuFragment());
drawer.setContentFragment(new ContentFragment());

SlidingRootNav:

new SlidingRootNavBuilder(this)
    .withMenuLayout(R.layout.menu_left_drawer)
    .withContentView(R.layout.activity_main)
    .inject();

Both libraries provide sliding drawer functionality for Android applications, but SlidingRootNav offers more flexibility and customization options. FantasySlide has a simpler implementation, making it easier for beginners to use. However, SlidingRootNav's active development and adherence to Material Design guidelines make it a more robust choice for long-term projects. The code comparison shows that FantasySlide requires less setup, while SlidingRootNav offers more configuration options in its builder pattern.

The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.

Pros of MaterialDrawer

  • More comprehensive and feature-rich, offering a wide range of customization options
  • Actively maintained with frequent updates and a large community
  • Extensive documentation and examples available

Cons of MaterialDrawer

  • Steeper learning curve due to its complexity and extensive features
  • Larger library size, which may impact app performance and size

Code Comparison

FantasySlide:

FantasyDrawerLayout fantasyDrawerLayout = (FantasyDrawerLayout) findViewById(R.id.fantasyDrawerLayout);
fantasyDrawerLayout.setTouchMode(FantasyDrawerLayout.TOUCH_MODE_FULLSCREEN);
fantasyDrawerLayout.setDrawerListener(new FantasyListener());

MaterialDrawer:

new DrawerBuilder()
    .withActivity(this)
    .withToolbar(toolbar)
    .addDrawerItems(
        new PrimaryDrawerItem().withName("Home"),
        new SecondaryDrawerItem().withName("Settings")
    )
    .build();

Summary

MaterialDrawer offers a more robust and feature-rich solution for implementing navigation drawers in Android applications. It provides extensive customization options and is actively maintained. However, this comes at the cost of increased complexity and a larger library size. FantasySlide, on the other hand, offers a simpler implementation with a focus on smooth animations but may lack some advanced features found in MaterialDrawer.

An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!

Pros of SlidingMenu

  • More mature and widely adopted project with a larger community
  • Offers extensive customization options and features
  • Supports both left and right sliding menus

Cons of SlidingMenu

  • No longer actively maintained (last commit in 2016)
  • Heavier implementation compared to FantasySlide
  • May require more setup and configuration

Code Comparison

FantasySlide implementation:

FantasySlideView slideView = findViewById(R.id.fantasy_slide_view);
slideView.setMenuItems(Arrays.asList(
    new MenuItem(R.drawable.ic_menu_1, "Menu 1"),
    new MenuItem(R.drawable.ic_menu_2, "Menu 2")
));

SlidingMenu implementation:

SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);

Summary

While SlidingMenu offers more features and customization options, FantasySlide provides a simpler and more lightweight implementation. SlidingMenu's maturity and extensive documentation make it a solid choice for complex projects, but its lack of recent updates may be a concern. FantasySlide, being more recent, offers a modern approach with smoother animations and easier integration, making it suitable for projects requiring a quick and visually appealing sliding menu implementation.

:octocat: 📃 FoldingCell is a material design expanding content cell inspired by folding paper material made by @Ramotion

Pros of folding-cell-android

  • More visually appealing and interactive UI element
  • Smooth animations and transitions
  • Customizable folding behavior and appearance

Cons of folding-cell-android

  • Limited to a specific UI component (folding cell)
  • May require more complex implementation for certain use cases
  • Potentially higher performance overhead due to animations

Code Comparison

FantasySlide:

mFantasyListener = new SimpleFantasyListener() {
    @Override
    public boolean onHover(@Nullable View view) {
        return false;
    }
};

folding-cell-android:

final FoldingCell fc = findViewById(R.id.folding_cell);
fc.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        fc.toggle(false);
    }
});

Summary

FantasySlide focuses on creating a sliding menu with customizable transformations, while folding-cell-android provides a specific folding cell UI component. FantasySlide offers more flexibility for menu-based layouts, whereas folding-cell-android excels in creating visually appealing expandable content cells. The choice between the two depends on the specific UI requirements and design goals of the project.

You can easily add awesome animated context menu to your app.

Pros of Context-Menu.Android

  • More polished and professional-looking UI with smooth animations
  • Extensive customization options for menu items and appearance
  • Better documentation and examples provided in the repository

Cons of Context-Menu.Android

  • Limited to circular menu layout, less flexible than FantasySlide
  • Potentially more complex to implement and customize for simpler use cases
  • Larger library size and potential performance impact due to advanced animations

Code Comparison

FantasySlide implementation:

FantasyDrawerLayout fantasyDrawerLayout = findViewById(R.id.drawer_layout);
fantasyDrawerLayout.setMenuListener(new SimpleMenuListener() {
    @Override
    public boolean onMenuItemClick(int position) {
        // Handle menu item click
        return true;
    }
});

Context-Menu.Android implementation:

MenuAdapter menuAdapter = new MenuAdapter(context, menuItems);
ContextMenuDialogFragment contextMenuDialogFragment = ContextMenuDialogFragment.newInstance(menuParams, menuAdapter);
contextMenuDialogFragment.show(fragmentManager, ContextMenuDialogFragment.TAG);

Both libraries offer unique approaches to creating custom menus in Android applications. FantasySlide provides a more flexible sliding drawer-style menu, while Context-Menu.Android focuses on a visually appealing circular context menu. The choice between the two depends on the specific design requirements and complexity of the project.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

FantasySlide

DOWNLOAD API Android Arsenal

一个 DrawerLayout 的扩展,具有帅气的动画与创新的交互。一次手势完成滑出侧边栏与选择菜单。欢迎下载 demo 体验。

https://raw.githubusercontent.com/mzule/FantasySlide/master/demo.apk

效果

使用方法

添加依赖

compile 'com.github.mzule.fantasyslide:library:1.0.5'

调用

调用方法基本与 DrawerLayout 一致. 本项目支持左右 (start left end right) 侧边栏同时定义。

<com.github.mzule.fantasyslide.FantasyDrawerLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/fake" />

    <com.github.mzule.fantasyslide.SideBar
        android:id="@+id/leftSideBar"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/colorPrimary"
        app:maxTranslationX="66dp">
        
        <!-- 这里是 SideBar 的子视图-->
        
    </com.github.mzule.fantasyslide.SideBar>
    <!-- 如果需要的话,可以添加右侧边栏-->
</com.github.mzule.fantasyslide.FantasyDrawerLayout>

  1. 最外层的 FantasyDrawerLayout 的使用与官方的 DrawerLayout 完全一致。
  2. SideBar 用来包装每一个菜单项,SideBar 本质上可以当做一个 vertical 的 LinearLayout 来使用。
  3. 效果图上的文字变色是表示该菜单处于 hover 状态, hover 状态默认会设定 view 的 pressed 状态为 true。可以通过 Listener 来改写, 下文会有详细说明。
  4. 详细参考 https://github.com/mzule/FantasySlide/blob/master/app/src/main/res/layout/activity_main.xml

进阶

maxTranslationX

通过设置 maxTranslationX 可以设置菜单项动画的最大位移。仅有在采用默认 Transformer 时才有效。

<com.github.mzule.fantasyslide.SideBar
	...
    app:maxTranslationX="88dp">

一般情况下,左边的侧边栏 maxTranslationX 为正数,右边的侧边栏 maxTranslationX 为负数。

Listener

支持设置 Listener 来监听侧边栏菜单的状态。

SideBar leftSideBar = (SideBar) findViewById(R.id.leftSideBar);
leftSideBar.setFantasyListener(new SimpleFantasyListener() {
    @Override
    public boolean onHover(@Nullable View view) {
    	return false;
    }

    @Override
    public boolean onSelect(View view) {
        return false;
    }

    @Override
    public void onCancel() {
    }
});
  1. Hover 是指上面效果图中,高亮的状态,此时手指仍在屏幕上 move. 默认的 hover 处理逻辑是设置 view 的 pressed 状态为 true. 重写 onHover(View) 方法返回 true 可以改写默认逻辑。
  2. Select 是指 hover 状态时手指离开屏幕,触发 select 状态。默认的处理逻辑是调用 view 的 onClick 事件。重写 onSelect(View) 方法返回 true 可以改写默认逻辑。
  3. Cancel 是指手指离开屏幕时,没有任何 view 触发 select 状态,则为 cancel,无默认处理逻辑。

Transformer

项目设计了一个 Transformer 接口,供调用者自定义菜单项的动画效果。使用方法类似于 ViewPager 的 PageTransformer.

class DefaultTransformer implements Transformer {
    private float maxTranslationX;

    DefaultTransformer(float maxTranslationX) {
        this.maxTranslationX = maxTranslationX;
    }

    @Override
    public void apply(ViewGroup sideBar, View itemView, float touchY, float slideOffset, boolean isLeft) {
        float translationX;
        int centerY = itemView.getTop() + itemView.getHeight() / 2;
        float distance = Math.abs(touchY - centerY);
        float scale = distance / sideBar.getHeight() * 3; // 距离中心点距离与 sideBar 的 1/3 对比
        if (isLeft) {
            translationX = Math.max(0, maxTranslationX - scale * maxTranslationX);
        } else {
            translationX = Math.min(0, maxTranslationX - scale * maxTranslationX);
        }
        itemView.setTranslationX(translationX * slideOffset);
    }
}

感谢

动画效果参考自 dribbble. https://dribbble.com/shots/2269140-Force-Touch-Slide-Menu 在此感谢。

另外,demo 里面 MainActivity 的右边栏实现了类似原作的菜单动画效果。具体可以参考相关代码。

许可

Apache License 2.0

联系我

任何相关问题都可以通过以下方式联系我。

  1. 提 issue
  2. 新浪微博 http://weibo.com/mzule
  3. 个人博客 https://mzule.github.io/
  4. 邮件 "mzule".concat("4j").concat("@").concat("gmail.com")