美文网首页
屏幕适配(AndroidAutoSize)

屏幕适配(AndroidAutoSize)

作者: 東方月初 | 来源:发表于2019-12-10 17:40 被阅读0次
  1. 添加依赖

    implementation 'me.jessyan:autosize:1.1.2'
    
  2. 清单文件中配置设计图尺寸

截屏2019-12-05下午3.42.49.png

如图所示 375x667 Ios 尺寸 约等于1080x1920 Android (为什么说约等于,因为3x完全一样,2x 1x 有差几像素)

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="GoogleAppIndexingWarning">
      ...
        <meta-data
            android:name="design_width_in_dp"
            android:value="375"/>
        <meta-data
            android:name="design_height_in_dp"
            android:value="667"/>
      ...
    </application>
  1. 设置预览

    (sqrt(纵向分辨率2+横向分辨率2))/25.4 求出屏幕尺寸

截屏2019-12-05下午3.51.28.png

预览选中自己新建的模拟器即可

截屏2019-12-05下午3.55.15.png

具体使用请参照官方文档 这里仅记录问题 配置完毕后 设计图表多少就可以直接写多少 比如15dp程序直接写15dp

相关文章

网友评论

      本文标题:屏幕适配(AndroidAutoSize)

      本文链接:https://www.haomeiwen.com/subject/abiggctx.html