Android SVG有多种尺寸吗? [英] Android SVG for multiple sizes?
问题描述
我当前正在使用标准24dp尺寸的PNG.但是,我需要一些大于100dp的图标.因此,我发现使用SVG代替大型PNG会更好.
I am currently using PNGs for standard 24dp size. However, I needed some icons larger than 100dp. So I found it would be better to use SVG instead of large size PNGs.
(使用gradle 2.0,Android支持lib 23.3)
(Using gradle 2.0, Android support lib 23.3)
一个图标属于普通共享图标.以前,我使用ic_share_white_24dp.png
在ActionBar上显示共享按钮.我需要使用大尺寸的共享"图标,因此我使用了Vector Asset Studio来导入"Material SVG Share"图标.导入后看起来像这样:
One icon is of a normal share icon. Previously I used, ic_share_white_24dp.png
for showing a share button on the ActionBar. I needed to use a large sized Share icon so I used Vector Asset Studio to import Material SVG Share icon. It looked like this after importing:
文件名: ic_share_white_48px.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z" />
</vector>
我将宽度和高度更改为100dp
.其背后的原因是在以下 API LOLLIPOP中使用此参数时,会生成PNG,并在以100dp的比例显示时会对其进行缩放.因此,我将24dp更改为100dp,以便Android Studio可以生成100dp PNG.
I changed width and height to 100dp
. The reason behind this is when this is used below API LOLLIPOP, PNGs are generated and are scaled when showing at 100dp. So, I changed 24dp to 100dp, so that Android Studio can generate 100dp PNGs.
现在,我也想在操作栏上使用此SVG.我应该创建一个高度和宽度设置为24dp的新xml吗?还是可以在缩小比例的情况下正常工作而不会出现任何性能问题?处理多尺寸图像的最佳方法是什么?
Now, I also want to use this SVG on an Action Bar too. Should I create a new xml with height and width set to 24dp? Or this will work just fine down scaled without any performance issues? What is the best method to work with multi-sized images?
最重要的是,我是否缺少一些了解的基础知识?
Most importantly, Am I missing some basics of understanding?
推荐答案
在这里您可以将SVG转换为.ttf文件并生成Unicode.将其放入资产/字体文件夹& 值"文件夹(icons.xml
)中的Unicode给出特定图标的字符串名称.
Here is a site where you convert SVG in .ttf file and generating Unicode. put that in asset/fonts folder & Unicode in Value folder(icons.xml
) give string name for particular icon.
示例:<string name="icon_info"></string>
在textView中使用此字符串
use this string in textView
<TextView
android:id="@+id/icon_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/icon_info"
android:textColor="@color/black"
android:textSize="40dp" />
在.java文件中
icon_info=(TextView)findViewById(R.id.icon_info);
Typeface font = Typeface.createFromAsset(this.getResources().getAssets(), "fonts/icons.ttf");
icon_info.setTypeface(font);
这篇关于Android SVG有多种尺寸吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!