Androidautosize
? A low-cost Android screen adaptation solution (今日头条屏幕适配方案终极版,一个极低成本的 Android 屏幕适配方案).
Under Apache License 2.0
By JessYanCoding
? A low-cost Android screen adaptation solution (今日头条屏幕适配方案终极版,一个极低成本的 Android 屏幕适配方案).
Under Apache License 2.0
By JessYanCoding
中文说明
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
Introduction Of Function
Framework Analysis
Common Issues
AndroidAutoLayout Migration Guide
Android Advanced Framework
gradle
implementation 'me.jessyan:autosize:1.2.1'
Step 1. Add the JitPack repository in your root build.gradle 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'
}
xml
<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>
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
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 {
}
```
First enable the ability to support Fragment custom parametersjava
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 {
}
```
java
AutoSizeConfig.getInstance().getUnitsManager()
.setSupportDP(false)
.setSupportSP(false)
.setSupportSubunits(Subunits.MM);
```
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.
```