Notice
-
Mainstream model equipment information can be used as reference
-
Summary of common problems of today's headline screen adaptation solution
-
For old projects, if you use AndroidAutoLayout , please refer to the AndroidAutoLayout migration guide . AndroidAutoSize can be used with AndroidAutoLayout . Because AndroidAutoLayout uses px , AndroidAutoSize will not have any impact on it. If some pages of the old project used dp before Layout, and AndroidAutoSize has had a bad effect on these pages . The old Activity that used dp can realize CancelAdapt to cancel the adaptation. It is recommended to use sub-units. Using sub-units will not affect the pages that previously used dp (nor Affects tripartite libraries and system controls), please see demo-subunits for details
Download
implementation 'me.jessyan:autosize:1.2.1'
Usage
Step 1 (really not bragging, only need the following step, the framework can adapt to all pages in the project)
- Please fill in the global design drawing size (unit dp) in AndroidManifest. If you use sub-units, you can fill in the pixel size directly without converting pixels to dp. For details, please see demo-subunits
Activity
- When the size of the design drawing of a certain Activity is different from the size of the global design filled in AndroidManifest, the CustomAdapt interface can be implemented to expand the adaptation parameters
public class CustomAdaptActivity extends AppCompatActivity implements CustomAdapt {
@Override
public boolean isBaseOnWidth() {
return false;
}
@Override
public float getSizeInDp() {
return 667;
}
}
- When an Activity wants to give up adaptation, please implement the CancelAdapt interface
public class CancelAdaptActivity extends AppCompatActivity implements CancelAdapt {
}
Fragment
- First turn on the function that supports Fragment custom parameters
AutoSizeConfig.getInstance().setCustomFragment(true);
- When the size of the design drawing of a certain Fragment is different from the size of the global design filled in AndroidManifest, the CustomAdapt interface can be implemented to expand the adaptation parameters
public class CustomAdaptFragment extends Fragment implements CustomAdapt {
@Override
public boolean isBaseOnWidth() {
return false;
}
@Override
public float getSizeInDp() {
return 667;
}
}
- When a Fragment wants to give up adaptation, please implement the CancelAdapt interface
public class CancelAdaptFragment extends Fragment implements CancelAdapt {
}
Subunits (please read demo-subunits carefully, there is a detailed introduction)
- You can choose one of the three unpopular units of pt, in, and mm as the sub-unit. The sub-unit is used to avoid the adverse effects on other system controls or tripartite library controls using dp layout caused by modifying DisplayMetrics#density . Use After the sub-unit, you can directly fill in the pixel size on the design drawing, no need to convert the pixel to dp
AutoSizeConfig.getInstance().getUnitsManager()
.setSupportDP(false)
.setSupportSP(false)
.setSupportSubunits(Subunits.MM);
DEOM:https://github.com/JessYanCoding/AndroidAutoSize
The publication is only for storage and convenience. If you have any copyright issues, please contact me in time.