不同分辨率手机适配小技巧

来源:互联网 发布:哔哩哔哩动画mac 编辑:程序博客网 时间:2024/06/08 06:01

如果需要适配不同的手机比如:480x800 和1280x800的分辨率,有种方式可以不需要重写布局文件而是只通过修改style文件来解决。如下

layout下有布局

<LinearLayout        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:background="@drawable/crm_list_top"        android:orientation="horizontal" >        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="center_vertical"            android:paddingLeft="8dp"            android:text="用户信息"            android:textColor="#404040" />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="center_vertical"            android:paddingLeft="5dp"            android:text="(请在已连接蓝牙的一体机上刷用户的身份证)"            style="@style/red_line"           />    </LinearLayout>


在values/style.xml中有一个样式:

 

<style name="red_line">      <item name="android:textColor">#FF8247</item>      <item name="android:textSize">13sp</item>  </style>


假设目前默认分辨率是480x800,则上边是480x800的样式,我们需要在新建values-1280x800文件夹来适配1280x800的分辨率

values-1280x800/style.xml中如下

  <style name="red_line">
      <item name="android:textColor">#FF8247</item>
      <item name="android:textSize">17sp</item>
  </style>


如果只是换图片的话可以新建一个drawable-hdpi-1280x800的文件夹。然后把相应的图片放进去即可