AndroidAutoSize README

The project's README from github.com/JessYanCoding/AndroidAutoSize. As one markdown file: README.md.

Logo Official

Latest Stable Version Build Status Min Sdk Version License Author QQ Group

中文说明

A low-cost Android screen adaptation solution (今日头条屏幕适配方案终极版,一个极低成本的 Android 屏幕适配方案).

Overview

Pixel 2 XL | 1440 x 2880 | 560dpi:

Pixel XL | 1440 x 2560 | 560dpi:

Nexus 5X | 1080 x 1920 | 420dpi:

Nexus 4 | 768 x 1280 | 320dpi:

Nexus S | 480 x 800 | 240dpi:

Notice

Download

Jcenter ( ⚠️ DEPRECATION WARNING: the JCenter repository will keep serving packages until February 1st, 2022):

 implementation 'me.jessyan:autosize:1.2.1'

JitPack:

Step 1. Add the JitPack repository in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.JessYanCoding:AndroidAutoSize:v1.2.1'
}

Usage

Step 1 (just one steps)

<manifest>
    <application>            
        <meta-data
            android:name="design_width_in_dp"
            android:value="360"/>
        <meta-data
            android:name="design_height_in_dp"
            android:value="640"/>           
     </application>           
</manifest>

Preview

DP

PT

IN

MM

Advance (see demo)

Activity

public class CustomAdaptActivity extends AppCompatActivity implements CustomAdapt {

    @Override
    public boolean isBaseOnWidth() {
        return false;
    }

    @Override
    public float getSizeInDp() {
        return 667;
    }
}
public class CancelAdaptActivity extends AppCompatActivity implements CancelAdapt {

}

Fragment

AutoSizeConfig.getInstance().setCustomFragment(true);
public class CustomAdaptFragment extends Fragment implements CustomAdapt {

    @Override
    public boolean isBaseOnWidth() {
        return false;
    }

    @Override
    public float getSizeInDp() {
        return 667;
    }
}
public class CancelAdaptFragment extends Fragment implements CancelAdapt {

}

Subunits (see demo-subunits)

AutoSizeConfig.getInstance().getUnitsManager()
        .setSupportDP(false)
        .setSupportSP(false)
        .setSupportSubunits(Subunits.MM);

About Me

License

 Copyright 2018, jessyan

   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.

AndroidAutoSize (JessYanCoding/AndroidAutoSize)

gradle
Searching Database…

What is this?AndroidAutoSize is an open-source Android screen adaptation library — the 'ultimate version' of Toutiao's density-based scheme — making one layout scale correctly across devices with very different screen sizes and densities.
Is it a library I add to my app, or a standalone tool I run?A library, not a standalone tool: you add it as a Gradle dependency to your Android app, and it scales your UI at runtime.
How do I add it to my Android project?Add the JitPack repository to your root build.gradle, add the dependency, then initialize in AndroidManifest — the README calls that one init the only required step ('just one steps'). The older JCenter repo is deprecated.
Is scaling everything by density completely safe, or is there a catch?It works by rewriting DisplayMetrics#density, which the README says can have adverse effects; optional pt/in/mm subunits avoid that and let you write design pixel sizes without converting to dp.
Is it Android-only, or does it cover other platforms too?Android only — it is a Java library built around Android's DisplayMetrics; the README demos it on Android phones from 240 dpi up to 560 dpi, with no iOS or web support mentioned.
How much work is the integration?Deliberately little — that is the 'low-cost' pitch: one Gradle dependency plus a single initialization in AndroidManifest. Per-Activity or Fragment tweaks and subunit support are all optional.
Which layout units does it support?dp and sp work out of the box. The pt, in and mm subunits must be enabled first via AutoSizeConfig.getInstance().getUnitsManager().setSupportSubunits(...).
Can I leave some screens out of the scaling?Yes. Any Activity can get custom adaptation parameters or be dropped from adaptation entirely; enable Fragment support first and Fragments can be tuned or cancelled the same way.
How do I preview a design accurately in Android Studio?Create a custom virtual device using the README formulas — for dp, screen size = sqrt(vertical^2 + horizontal^2)/dpi — and optionally pick the panel theme that hides the status and navigation bars so the preview fills the page.
Size
3.1 MB
Stars
13.7K
Age
8y
Commits · 90 Days