1. 程式人生 > >使用SVG圖片格式

使用SVG圖片格式

rip loop fun graphics ima title res sim 主動

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.

‘).addClass(‘pre-numbering‘).hide(); $(this).addClass(‘has-numbering‘).parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($(‘
  • ‘).text(i)); }; $numbering.fadeIn(1700); }); });

    使用SVG圖片格式