Skip to content
🔥 A low-cost Android screen adaptation solution (今日头条屏幕适配方案终极版,一个极低成本的 Android 屏幕适配方案).
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Update ISSUE_TEMPLATE.md Sep 26, 2018
art Update art/unit_dp.png Sep 12, 2018
autosize 重大更新: 同时兼容 Androidx 和 Support, 框架会根据您项目的依赖情况自动选择对应的 Library Jan 21, 2020
demo-androidx 新增: Androidx Demo Jan 21, 2020
demo-subunits 新增: Androidx Demo Jan 21, 2020
demo 新增: Androidx Demo Jan 21, 2020
gradle/wrapper
.gitignore Init commit Aug 8, 2018
.travis.yml Update .travis.yml Jan 21, 2020
CHANGELOG.md Create CHANGELOG.md Oct 31, 2018
LICENSE Initial commit Aug 17, 2018
README-zh.md
README.md Update README.md Mar 29, 2019
_config.yml Set theme jekyll-theme-modernist Oct 18, 2018
build.gradle 重大更新: 同时兼容 Androidx 和 Support, 框架会根据您项目的依赖情况自动选择对应的 Library Jan 21, 2020
gradle.properties Init commit Aug 8, 2018
gradlew
gradlew.bat Init commit Aug 8, 2018
settings.gradle 新增: Androidx Demo Jan 21, 2020

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

 implementation 'me.jessyan:autosize:1.1.2'

Usage

Step 1 (just one steps)

  • Initialize in AndroidManifest, if you use a subunits, you can write the pixel size, no need to convert the pixel to dp, please see demo-subunits
<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

  • Real-time preview during layout is an important part of the development phase, in many cases, the default preview device provided by Android Studio does not fully display our design, so we need to create the virtual device ourselves, under the dp, pt, in, mm four units of virtual device creation method

  • If you don't want the status bar and navigation bar to appear in Preview during preview, you can select the panel theme according to the following image, after using this theme, the vertical resolution just fills the entire preview page theme

  • Virtual device creation method create step

DP

  • If you use dp as a unit in the layout file for layout (AndroidAutoSize supports dp, sp for layout by default), you can find the screen size according to the formula (sqrt(vertical resolution^2 + horizontal resolution^2))/dpi and create an virtual device (write screen size and resolution only) dp

PT

  • If you use pt as a unit in the layout file for layout (requires AutoSizeConfig.getInstance().getUnitsManager().setSupportSubunits(Subunits.PT); to open pt support), you can find the screen size according to the formula (sqrt(vertical resolution^2 + horizontal resolution^2))/72 and create an virtual device (write screen size and resolution only) pt

IN

  • If you use in as a unit in the layout file for layout (requires AutoSizeConfig.getInstance().getUnitsManager().setSupportSubunits(Subunits.IN); to open in support), you can find the screen size according to the formula sqrt(vertical resolution^2 + horizontal resolution^2) and create an virtual device (write screen size and resolution only) in

MM

  • If you use mm as a unit in the layout file for layout (requires AutoSizeConfig.getInstance().getUnitsManager().setSupportSubunits(Subunits.MM); to open mm support), you can find the screen size according to the formula (sqrt(vertical resolution^2 + horizontal resolution^2))/25.4 and create an virtual device (write screen size and resolution only) mm

Advance (see demo)

Activity

  • Customize the adaptation parameters of the Activity:
public class CustomAdaptActivity extends AppCompatActivity implements CustomAdapt {

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

    @Override
    public float getSizeInDp() {
        return 667;
    }
}
  • Cancel the adaptation of the Activity:
public class CancelAdaptActivity extends AppCompatActivity implements CancelAdapt {

}

Fragment

  • First enable the ability to support Fragment custom parameters
AutoSizeConfig.getInstance().setCustomFragment(true);
  • Customize the adaptation parameters of the Fragment:
public class CustomAdaptFragment extends Fragment implements CustomAdapt {

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

    @Override
    public float getSizeInDp() {
        return 667;
    }
}
  • Cancel the adaptation of the Fragment:
public class CancelAdaptFragment extends Fragment implements CancelAdapt {

}

Subunits (see demo-subunits)

  • You can choose one of the three unpopular units of pt, in, mm as the subunits, the subunits is used to avoid the adverse effects caused by modifying DisplayMetrics#density, after using the subunits, you can write the pixel size on the design, you don't need to convert it to dp
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.
You can’t perform that action at this time.