使用SVG圖片格式
SVG格式, 適應屏幕, 圖片較小, 還有非常多長處, 參考. 本文解說怎樣使用SVG格式.
SVG: Scalable Vector Graphics, 可縮放矢量圖形.
IRI: Internationalized Resource Identifiers, 國際化資源標識符.
下載SVG格式的圖片.
新建項目, 空白項目顯示圖片.
Android Studio 2.0
路徑: File -> New -> Vector Asset -> Local SVG file
勾選重置圖片大小和左右布局適配.
在drawable
.xml
格式的圖片.
代碼中導入圖片.
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@null"
android:src="@drawable/homer_simpson"/>
顯示
假設是非AS2.0
版本號, 我們能夠使用在線站點轉換.
網址: http://inloop.github.io/svg2android/
上傳SVG圖片, 生成代碼.
勾選刪除空組和加入變換.
能夠下載在線圖片, 也能夠在drawable
目錄中, 創建.xml
文件, 粘貼代碼.
使用方式與自己主動生成的相似, 直接加入就可以.
通過觀察發現, 均是500x500的圖片:
自己主動生成的SVG圖片是20KB, 在線生成的SVG圖片是29KB.
而PNG(放大的系統圖片)要732KB, 由此得知SVG圖片還是非常節省內存的.
對於一些較大的App, 使用SVG圖片有非常大的吸引力.
Github下載地址
OK, Enjoy It.
使用SVG圖片格式