閱讀930 返回首頁    go 阿裏雲 go 技術社區[雲棲]


android多屏幕分辨率適配

做android開發,開源嘛,滿市場都是淩亂的機型,總少不了適配這樣或那樣的型號。在這裏分享一下自己在開發中用到的方法。

首先要介紹一下drawable-mdpi、drawable-hdpi-1280x800、drawable-hdpi。這個相信好好看一下也明白。就是代表著分辨率 320X480、1280X800、480X800三款屏幕圖片資源包。其實適配也很多。我大致說一種就行,其他大家慢慢琢磨,或上網周轉。



說明一下這個圖的意思,就是我要說的配置方法,就是一套圖片資源(資源文件要看美工的設計了。最好能是XXX.9.png)配一套布局文件及多套數值文件。


布局文件:


  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="https://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>  
數值文件:
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <!-- values-hdpi 480X800 -->  
  4.     <dimen name="imagewidth">320dip</dimen>      
  5. </resources>  

  1. <resources>  
  2.     <!-- values-hdpi-1280x800 -->  
  3.     <dimen name="imagewidth">320dip</dimen>      
  4. </resources>  

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <!-- values-hdpi  480X320 -->  
  4.     <dimen name="imagewidth">320dip</dimen>      
  5. </resources> 

最後更新:2017-04-03 12:55:04

  上一篇:go 設計模式之簡單模式與策略模式
  下一篇:go 安卓作品:河北空氣質量客戶端