Git Product home page Git Product logo

mondrian-layout's Introduction

#MondrianLayout

alt text alt text

MondrianLayout allows to create Android layouts with the containing elements disposed in a pure grid organization. You just define the size of your grid and the cells occupied by each element inside.

You can:

  • Dispose elements in the layout indicating the starting coordinates in the grid and the width and height in cells
  • Overlap elements, the ones declared later in the layout will be on top of the ones declared before
  • Nest MondrianLayouts, so you can have a grid that contains an element with its own Grid

Getting MondrianLayout

Just add the following to your build.gradle file

  compile 'com.worldline:mondrianlayout:1.0.0'

Usage

First, add a namespace into your layout for the non-system resources, for example:

    xmlns:mondrian="http://schemas.android.com/apk/res-auto"

Now you can include a MondrianLayout into your layout:

<com.worldline.mondrian.MondrianLayout
        android:id="@+id/mondrian"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000"
        mondrian:borderRatio="12"
        mondrian:columns="6"
        mondrian:rows="8">

The specific attributes are:

  • columns: number of columns of the grid
  • rows: number of rows of the grid
  • borderRatio: size of the border between cells. The resulting width of the cell will be divided by this number to get the size of the border

Now you can put elements inside your MondrianLayout:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="#303F9F"
            android:gravity="center"
            android:text="1"
            android:textColor="@android:color/white"
            android:textSize="20sp"
            mondrian:layout_column="0"
            mondrian:layout_height="1"
            mondrian:layout_row="0"
            mondrian:layout_width="4" />

Here the attributes:

  • android:layout_width/android:layout_height: these two attributes are not used, but Android forces to include them in the definition of the View. Just set any value, it will be ignored.
  • layout_column/layout_row: starting column/row where to put this view. Columns and rows start in zero until size-1
  • layout_width/layout_height: number of cells this view will occupy in width/heigh

You can also nest MondrianLayout elements one inside of the another, so the child MondrianLayout could have a different column/row configuration than its ancestor.

The sample app has a layout with several examples, including nested ones.

TODO

There are still some things to improve, including:

  • Ability to change grid properties during runtime
  • Ability to animate cell size/position
  • Do something with the android:layout_width/android:layout_height property, as having to include it not to be used is not an elegant solution

Anything else, feel free to post an Issue or perform a Pull Request

LICENSE

Copyright 2015 Wordline Spain

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

mondrian-layout's People

Contributors

sergiandreplace avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

Forkers

marciopocebon

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.