ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

在Android中使用矢量图标

2019-05-20 14:19:53  阅读:554  来源: 互联网

标签:android xml android-imageview android-actionbar vector-graphics


为此序言:

我已经考虑过将它放在graphicdesgin.stackexchange.com上,但我得出结论,我的Android特定问题可能不是最好的地方.这就是我选择stackoverflow的原因,因为它似乎更像是Android imageViews然后是图形本身的问题.谢谢.

我需要在Android应用程序中使用一些基本图标.我有Illustrator和Photoshop(在任何一个都不是很好,但我可以顺利).我偶然发现了http://www.androidicons.com/,我看到很有可能只用25美元就节省了几个小时的时间.为了了解在我的应用程序中使用它们需要做些什么,我下载了免费的“BONUS ICONS 01”包.

我决定尝试使用时钟图标,看看它在我的应用程序中是如何工作的.我在Illustrator中将图标放大到大约800px,然后将其复制并粘贴到Photoshop中.我把它保存为.png,然后我创建了一个示例应用程序来测试它.

图像只被放入xhdpi文件夹中,因为我可能会将此图标用于大于操作栏的内容,但不会占用整个屏幕.我的想法是,如果你要为所有单独的dpi级别创建操作栏图标,那么你必须确切地知道你将要制作它们的大小(以像素为单位),因此它们看起来都非常好(例如,如果您从谷歌下载操作栏图标,他们会以几种尺寸向您提供,而不仅仅是一种尺寸.但是,如果他们将被用于比这更大的东西呢?我怎么知道要制作它们的尺寸.

要真实地表达我对如何无法理解这个主题的沮丧.这是我的应用程序的代码,以及它最终看起来像我的Galaxy Nexus的结果.较大的图标很好,而较小的图标看起来不那么清晰.我该如何解决?在Illustrator中制作图像并进入Photoshop并确保它们在任何尺寸下都能使用它们的正确方法是什么?

此致

Android开发人员只是不懂图形.

正如你所看到的那样,当图像很大时,它看起来看起来很不错,但是当图像较小时使用它会导致IMO出现一些问题.有办法解决这个问题吗?我太挑剔了吗?即使我将它调整为更小,并将其放入mdpi,我的布局是否会选择它?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center|center_horizontal" >

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/anti_huge"
                android:layout_weight="1" />

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/anti_huge"
                android:layout_weight="1" />
            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/anti_huge"
                android:layout_weight="1" />
            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/anti_huge"
                android:layout_weight="1" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:gravity="center|center_horizontal" >

            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/anti_huge" />

        </LinearLayout>

    </LinearLayout>

</RelativeLayout>

问题摘要:

>但是,如果他们将被用于更大的东西呢?
那? (“那个”= ActionBarIcons)
>我怎么知道什么尺寸
制作它们? (ActionBarIcons是由Google提供给我的
像素尺寸,他们是如何计算这些尺寸的)
>我该如何解决这个问题? (测试应用程序上的大图标看起来很好,而
较小的看起来参差不齐)
>制作图像的正确方法是什么?
Illustrator并转向Photoshop并确保它们看起来很棒
在任何尺寸他们被使用?
>有什么办法解决这个问题吗?
>我也是
挑剔? (请告诉我,我……这场考验正在扼杀我.)
>即使我将它重新调整为更小,并将其放入mdpi,我的布局也是如此
甚至选择了吗?

解决方法:

你做得不对;)

Android会根据最接近的匹配对图像进行缩放.如果您只提供一个(非常大的)位图,那么Android会将其缩放到您请求的较小尺寸.如果你这样做,你将失去抗锯齿,图标看起来就像你的那样.

您要做的是将png导出到使用它时实际需要的(物理)大小,然后导出到所需的屏幕密度.

可点击区域的最小建议大小为40x40dp,转换为1/4“方形.有可能,您将使用10%边框,因此最终可以使用mdpi中的32×32像素图标.

因此,现在您在32×32中渲染矢量图像以获得mdpi(160dpi),将24×24渲染为ldpi(120dpi),将48×48渲染为hdpi(240dpi),将64×64渲染为xhdpi(320dpi).

如果您希望相同的图标更大,请将其渲染为单独的资源.假设你想要一个2×2的时钟水印,你将在320x320px渲染mdpi,等等.

您在布局中将图像指定为200dp x 200dp,Android将根据设备分辨率在屏幕上提取正确的图像.

对于一些重复渲染,我使用Android Asset Studio.您可以设置颜色,图标,效果等,它允许您下载所有分辨率的一组图标.

标签:android,xml,android-imageview,android-actionbar,vector-graphics
来源: https://codeday.me/bug/20190520/1143818.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有