The Ultimate Edition of Toutiao Screen Adaptation Solution, a very low-cost Android screen adaptation solution.

 

Notice

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.

Guess you like

Origin blog.csdn.net/q992767879/article/details/112779580