Baike.dev
All toolsTrendingOpen sourceNewsSubmit
Log in
< 返回工具列表
A

AndroidAutoSize

> 编程语言
开源

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

13.7K stars0 点赞3 次浏览
访问官网GitHub

工具介绍

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

中文说明

## 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 * [Devices Info](https://material.io/tools/devices/) * [Introduction Of Function](https://juejin.im/post/5bce688e6fb9a05cf715d1c2) * [Framework Analysis](https://juejin.im/post/5b7a29736fb9a019d53e7ee2) * [Common Issues](https://github.com/JessYanCoding/AndroidAutoSize/issues/13) * [AndroidAutoLayout Migration Guide](https://github.com/JessYanCoding/AndroidAutoSize/issues/90) * [Android Advanced Framework](https://github.com/JessYanCoding/MVPArms) ## Download ### Jcenter ([ ⚠️ DEPRECATION WARNING: the JCenter repository will keep serving packages until February 1st, 2022](https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter)): ``` gradle implementation 'me.jessyan:autosize:1.2.1' ``` ### JitPack: Step 1. Add the JitPack repository in your root [build.gradle](https://github.com/JessYanCoding/AndroidAutoSize/blob/master/build.gradle#L20) at the end of repositories: ```gradle allprojects { repositories { ... maven { url "https://jitpack.io" } } } ``` Step 2. Add the dependency ```gradle dependencies { implementation 'com.github.JessYanCoding:AndroidAutoSize:v1.2.1' } ``` ## 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](https://github.com/JessYanCoding/AndroidAutoSize/tree/master/demo-subunits)** ```xml ``` ## 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 * Virtual device creation method ### 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**) ### 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**) ### 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**) ### 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**) ## Advance (see demo) ### Activity * **Customize the adaptation parameters of the Activity:** ```java 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:** ```java public class CancelAdaptActivity extends AppCompatActivity implements CancelAdapt { } ``` ### Fragment * **First enable the ability to support Fragment custom parameters** ```java AutoSizeConfig.getInstance().setCustomFragment(true); ``` * **Customize the adaptation parameters of the Fragment:** ```java 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:** ```java 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** ```java AutoSizeConfig.getInstance().getUnitsManager() .setSupportDP(false) .setSupportSP(false) .setSupportSubunits(Subunits.MM); ``` ## About Me * **Email**: * **Home**: * **掘金**: * **简书**: ## 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. ```

核心特点

  • •Devices Info
  • •Introduction Of Function
  • •Framework Analysis
  • •Common Issues
  • •AndroidAutoLayout Migration Guide
  • •Android Advanced Framework
  • •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
  • •Virtual device creation method
  • •Customize the adaptation parameters of the Activity:
  • •Cancel the adaptation of the Activity:

> 标签

Javaadapterviewandroidarmsdensity

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月9日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言
Baike.dev

baike.dev helps you discover great languages, frameworks, databases, DevOps and cloud-native tools.

Quick links

  • Home
  • All tools
  • Trending
  • Open source

About

  • About us
  • Community
  • News

Contribute

Found a great developer tool? Share it with the community.

Submit a tool
© 2026 baike.dev Developer EncyclopediaUpdated daily · Discover great developer tools