Code Monkey home page Code Monkey logo

slidingmenulayout's Introduction

SlidingMenuLayout

A custom layout for Android that reveals a menu lying underneath another view.

Description

This project is aimed to provide a very basic implementation of a layout to implement sliding menu's like those found in the Facebook, Spotify or Firefox apps, for example.

Objectives

  • Simplicity - This solution only requires adding a single class to your own project, and can be used with a minimal amount of glue code.
  • Flexibility - This solution only provides the bare minimum to implement a sliding menu. You will have maximum flexibility to go from there (in fact, the bottom view that is revealed doesn't even really have to be a menu).
  • Compatibility - The solution works on old Android versions. Personally I make sure it works at least on Android 2.2. Also, I make sure this solution can be used as a drop-in solution with PhoneGap / Cordova projects.

Usage

First, copy the file SlidingMenuLayout.java into your project.

Second, use the SlidingMenuLayout as root view for your Activity. To accomplish this with the least amount of modification to existing code, you can override your Activity's setContentView() as follows:

    @Override
    public void setContentView(View view) {

        SlidingMenuLayout layout = new SlidingMenuLayout(this);
        layout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 0.0F));

        layout.addView(new MenuView(this));

        layout.addView(view);

        super.setContentView(layout);
    }

In this example, MenuView is the view that will actually show the menu. It is up to you to implement this view.

Finally, you can add a button (typically in the top left corner of your main view), that calls openMenu() or closeMenu() on the layout as appropriate. This also is left as an exercise to the reader. You may also want to implement swipe movements for opening/closing the menu.

slidingmenulayout's People

Contributors

arendjr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.