Git Product home page Git Product logo

autoscalinglayout's Introduction

AutoScalingLayout

Auto-Scaling Layouts for Android.

        compile 'me.dreamheart.autoscalinglayout:lib:1.6.2'
    Eclipse users import release/AutoScalingLayout.jar, and copy attr.xml into value folder.

Replace the Layout:

All we need is to replace the root layouts required auto-scaling, the child layouts will also achieve auto-scaling.

Original layout AutoScalingLayout
RelativeLayout ASRelativeLayout
LinearLayout ASLinearLayout
FrameLayout ASFrameLayout

For now the three layouts above are supported.

Add the attribute:

designWidth and designHeight are the screen sizes you are using when you are designing the GUI in the xml editor. For instance, I use Nexus 4 as my design device (I treat all the devices as Nexus 4), so the generic screen size converting to dp is 384dp and 575dp (exclude the statebar and the actionbar).

autoScaleEnable use to enable/disable scaling.

autoScaleType can be "fitInside", "fitWidth" and "fitHeight"

<me.dreamheart.autoscalinglayout.ASRelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    custom:designWidth="384dp"
    custom:designHeight="575dp"
    custom:autoScaleEnable="true"
    custom:autoScaleType="fitInside"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".LoginActivity"
    android:background="@drawable/login_bg"
    >
  1. designWidth and designHeight are very import. If you assign wrong values, you would not see the expected layouts.
  2. The unit used in the xml GUI editor should keep constant. For example, if you use dp for designWidth and designHeight, all the unit of the child views has to be dp, even the font size can not be sp, so as px, pt. If you just want to copy the pixel values given by GUI, just use px for all components.
  3. When applying AutoScalingLayout, the screen will keep the aspect ratio of designWidth and designHeight, so don’t worry about turning square layouts into rectangle unexpectedly.

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.