在Android中使用矢量图标

EGH*_*HDK 5 xml android vector-graphics android-imageview android-actionbar

为此序言:

我已经考虑过将它放在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>
Run Code Online (Sandbox Code Playgroud)

问题摘要:

  1. 但是,如果他们将被用于比这更大的东西呢?("那个"= ActionBarIcons)
  2. 我怎么知道它们的尺寸是多少?(ActionBarIcons是由谷歌提供给我的设置像素尺寸,他们是如何计算这些尺寸的)
  3. 我该如何解决?(测试应用程序上的大图标看起来很好,而较小的图标看起来很锯齿)
  4. 在Illustrator中制作图像并进入Photoshop并确保它们在任何尺寸下都能使用它们的正确方法是什么?
  5. 有办法解决这个问题吗?
  6. 我太挑剔了吗?(请告诉我,我......这场考验正在扼杀我.)
  7. 即使我将它重新调整为更小,并将其放入mdpi,我的布局是否会选择它?

323*_*3go 3

你做得不对;)

Android 根据最接近的匹配比例缩放图像。如果您只提供一张(非常大的)位图,那么 Android 会将其缩放到您请求的较小尺寸。如果您这样做,您将失去抗锯齿功能,并且图标将看起来像您的一样。

您需要的是将 png 导出为您在使用时实际需要的(物理)尺寸,然后导出为所需的屏幕密度。

可点击区域的最小建议尺寸是 40x40dp,即 1/4" 正方形。您可能会使用 10% 边框,因此最终会得到一个 mdpi 中的 32x32 像素图标。

因此,现在您可以将矢量图像渲染为 32x32(mdpi)(160dpi)、24x24(ldpi)(120dpi)、48x48(hdpi)(240dpi)和 64x64(xhdpi(320dpi))。

如果您希望同一图标更大,请将其渲染为单独的资源。假设您想要时钟的 2x2" 水印,您将按照 mdpi 等将其渲染为 320x320px。

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

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