Code Monkey home page Code Monkey logo

ratiolayouts's Introduction

Download

Depricated

With introduction of ConstraintLayout you don't have to write either a single line of code or use third-parties.

Here's the example of how to keep 1:1 aspect ratio for your layout using ConstraintLayout:

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"
        android:layout_marginTop="0dp"
        android:background="@android:color/black"
        app:layout_constraintDimensionRatio="H,1:1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

   </View>

</android.support.constraint.ConstraintLayout>

Ratio Layouts

A collection of ViewGroups which can have a constant width to height ratio.

Demo

Ratio Layouts (APK)

Assign a ratio and never worry about your views looking out of propotions.

Installation

Gradle

dependencies {
    compile "com.ritesh:ratiolayout:${latestVersion}"
}

Usage

Define 'app' namespace on root view in your layout

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

Include this library in your layout

<com.ritesh.ratiolayout.RatioRelativeLayout
        android:id="@+id/activity_main_ratio_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:fixed_attribute="WIDTH"
        app:horizontal_ratio="1"
        app:vertical_ratio="1">

Supported Attributs

XML Attribut Programmatical Getters Description
app:fixed_attribute getFixedAttribute() Set one side of the layout as fixed, calculating the other based on this
app:horizontal_ratio getHorizontalRatio() Horizontal aspect ratio.
app:vertical_ratio getVerticalRatio() Vertical aspect ratio.

Supported Layouts

  • RatioFrameLayout
  • RatioGridLayout
  • RatioLinearLayout
  • RatioRelativeLayout
  • RatioTableLayout

Supported Java Setters

  • setRatio(float horizontalRatio, float verticalRatio) - Sets ratios
  • setRatio(FixedAttribute fixedAttribute, float horizontalRatio, float verticalRatio) - Sets ratios along with Fixed Side.

Contact me

If you have a better idea or way on this project, please let me know, thanks :)

Email

License

This project is licensed under the MIT License - see the LICENSE.md file for details

ratiolayouts's People

Contributors

freitzzz avatar riteshakya037 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

samr31

ratiolayouts's Issues

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.