android 屏幕适配小结

来源:互联网 发布:蓝月传奇羽毛进阶数据 编辑:程序博客网 时间:2024/06/07 04:03

做android开发,开源嘛,满市场都是凌乱的机型,总少不了适配这样或那样的型号。在这里分享一下自己在开发中用到的方法。

首先要介绍一下drawable-mdpi、drawable-hdpi-1280x800、drawable-hdpi。这个相信好好看一下也明白。就是代表着分辨率 320X480、1280X800、480X800三款屏幕图片资源包。其实适配也很多。我大致说一种就行,其他大家慢慢琢磨,或上网周转。



说明一下这个图的意思,就是我要说的配置方法,就是一套图片资源(资源文件要看美工的设计了。最好能是XXX.9.png)配一套布局文件及多套数值文件。


布局文件:


[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <ImageView  
  8.         android:layout_width="@dimen/imagewidth"  
  9.         android:layout_height="wrap_content"  
  10.         android:background="@drawable/ic_launcher" />  
  11.   
  12. </LinearLayout>  
数值文件:

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <!-- values-hdpi 480X800 -->  
  4.     <dimen name="imagewidth">120dip</dimen>      
  5. </resources>  

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <resources>  
  2.     <!-- values-hdpi-1280x800 -->  
  3.     <dimen name="imagewidth">220dip</dimen>      
  4. </resources>  

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <!-- values-hdpi  480X320 -->  
  4.     <dimen name="imagewidth">80dip</dimen>      
  5. </resources>  
0 0
原创粉丝点击