2016-11-09 187 views
1

我有以下矢量绘制:矢量绘制

<?xml version="1.0" encoding="utf-8"?> 
<vector xmlns:android="http://schemas.android.com/apk/res/android" 
    android:width="25dp" 
    android:height="25dp" 
    android:viewportWidth="25" 
    android:viewportHeight="25"> 

    <path 
     android:fillColor="#FFFFFF" 
     android:fillType="evenOdd" 
     android:strokeWidth="1" 
     android:pathData="M12.5,25 C19.4035594,25 25,19.4035594 25,12.5 C25,5.59644063 19.4035594,0 12.5,0 
C5.59644063,0 0,5.59644063 0,12.5 C0,19.4035594 5.59644063,25 12.5,25 Z M12.5,24 
C18.8512746,24 24,18.8512746 24,12.5 C24,6.14872538 18.8512746,1 12.5,1 
C6.14872538,1 1,6.14872538 1,12.5 C1,18.8512746 6.14872538,24 12.5,24 Z M16,6 
C17.6568542,6 19,7.34226429 19,8.99878564 L19,16.0012144 C19,17.6573979 
17.6534829,19 16,19 C14.3431458,19 13,17.6577357 13,16.0012144 L13,8.99878564 
C13,7.34260206 14.3465171,6 16,6 Z M14,16.0012144 C14,17.1052262 14.8952058,18 
16,18 C17.1026267,18 18,17.1036857 18,16.0012144 L18,8.99878564 C18,7.89477378 
17.1047942,7 16,7 C14.8973733,7 14,7.89631432 14,8.99878564 L14,16.0012144 Z 
M8.33473905,12.5 C8.14415114,12.3451212 7.57820716,11.8273213 
7.57820716,11.8273213 C6.80306599,11.0695455 6,10.0347728 6,9 C6,7 7,6 9,6 C11,6 
12,7 12,9 C12,10.0347728 11.196934,11.0695455 10.4217928,11.8273213 
C10.4217928,11.8273213 9.85584886,12.3451212 9.66526095,12.5 
C9.85584886,12.6548788 10.4217928,13.1726787 10.4217928,13.1726787 
C11.196934,13.9304545 12,14.9652272 12,16 C12,18 11,19 9,19 C7,19 6,18 6,16 
C6,14.9652272 6.80306599,13.9304545 7.57820716,13.1726787 C7.57820716,13.1726787 
8.14415114,12.6548788 8.33473905,12.5 Z M9.03460423,12 C10.1996214,11.0532638 
11,9.74316 11,9 C11,7.55228475 10.4477153,7 9,7 C7.55228475,7 7,7.55228475 7,9 
C7,9.74316 7.86958707,11.0532638 9.03460423,12 L8.96539577,13 
C7.80037862,13.9467362 7,15.25684 7,16 C7,17.4477153 7.55228475,18 9,18 
C10.4477153,18 11,17.4477153 11,16 C11,15.25684 10.1304129,13.9467362 
8.96539577,13 L9.03460423,12 Z" /> 
</vector> 

在Android Studio中预览选项卡它看起来像这样(这是需要什么):

enter image description here

但是当我以编程方式将其设置为ImageView作为其源时,代码为:

imageMenuItem.setImageResource(R.drawable.keno); 

它看起来像这样:

enter image description here

XML代码为ImageView很简单:

<ImageView 
    android:id="@+id/image_menu_item" 
    style="@style/UpperItemsImageLeftMenu" 
    app:srcCompat="@drawable/leftmenu_keno" 
    android:layout_width="@dimen/upper_item_image_dim_left_menu" 
    android:layout_height="@dimen/upper_item_image_dim_left_menu" 
    /> 

深灰色的背景是,在其他地方设置。有谁知道我该如何解决这个问题?

+1

根据我的经验,Vector Drawables不支持'evenOdd'填充规则,所以路径需要重新定向以正确显示https://developer.mozilla.org/en/docs/Web/SVG/Attribute/fill-rule – Duopixel

+1

@Duopixel可以调出填充规则,尽管我会添加更多的细节。 VectorDrawable默认填充规则是“非零”;改变填充规则只是在API 24中引入的。所以,你应该坚持“非零”尝试配置你的矢量图形软件给你。一些链接: https://medium.com/@dineshbob10/the-mystery-of-the-disappearing-holes-a-gripping-tale-of-using-svg-in-android-442f6035a452#.hnq7fat30 https: //blog.stylingandroid.com/vectordrawable-fill-windings/ –

+1

@Duopixel @Lewis,你是对的。我从xml中移除了'android:fillType =“evenOdd”',预览显示了实心圆。非常感谢你!太糟糕了,你没有回答,但评论它,因为我不能设置正确的答案。 –

回答

4

好的,这里是解决方案。

问题

问题的来源是与XML的填充规则:android:fillType="evenOdd"。 Android不支持此参数,直到Nougat版本,所以我们必须以某种方式避免它。正如@LewisMcGeary指出的那样,在这个顶点上有一个很好的解释:Marc Allison's blog。按照@Duopixel的建议,可以在this link上找到有关此填充规则的更多信息。

我的解决方案

我通过改变软件解决了这个问题。我用这个online tool如之前提到的博客文章,设置如下建议:

enter image description here

,然后我救了它与下面的内容,以XML:

<?xml version="1.0" encoding="utf-8"?> 
<vector 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:auto="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" 
    tools:ignore="NewApi" 
    android:viewportWidth="25" 
    auto:viewportWidth="25" 
    android:viewportHeight="25" 
    auto:viewportHeight="25" 
    android:width="25dp" 
    auto:width="25dp" 
    android:height="25dp" 
    auto:height="25dp"> 
    <path 
     android:pathData="M12.5 25C19.40356 25 25 19.40356 25 12.5C25 5.596441 19.40356 0 12.5 0C5.596441 0 0 5.596441 0 12.5C0 19.40356 5.596441 25 12.5 25M16 6C17.65685 6 19 7.342264 19 8.998786L19 16. 00121C19 17.6574 17.65348 19 16 19C14.34315 19 13 17.65774 13 16.00121L13 8.998786C13 7.342602 14.34652 6 16 6M14 16.00121C14 17.10523 14.89521 18 16 18C17.10263 18 18 17.10369 18 16.00121L18 8. 998786C18 7.894774 17.10479 7 16 7C14.89737 7 14 7.896314 14 8.998786L14 16.00121M8.334739 12.5C8.144151 12.34512 7.578207 11.82732 7.578207 11.82732C6.803066 11.06955 6 10.03477 6 9C6 7 7 6 9 6C11  6 12 7 12 9C12 10.03477 11.19693 11.06955 10.42179 11.82732C10.42179 11.82732 9.855849 12.34512 9.665261 12.5C9.855849 12.65488 10.42179 13.17268 10.42179 13.17268C11.19693 13.93046 12 14.96523 12  16C12 18 11 19 9 19C7 19 6 18 6 16C6 14.96523 6.803066 13.93046 7.578207 13.17268C7.578207 13.17268 8.144151 12.65488 8.334739 12.5M9.034604 12C10.19962 11.05326 11 9.74316 11 9C11 7.552285 10.44771  7 9 7C7.552285 7 7 7.552285 7 9C7 9.74316 7.869587 11.05326 9.034604 12M8.965396 13C7.800378 13.94674 7 15.25684 7 16C7 17.44772 7.552285 18 9 18C10.44771 18 11 17.44772 11 16C11 15.25684 10.13041 13 .94674 8.965396 13M12.5 24C6.148726 24 1 18.85127 1 12.5C1 6.148726 6.148726 1 12.5 1C18.85127 1 24 6.148726 24 12.5C24 18.85127 18.85127 24 12.5 24" 
     auto:pathData="M12.5 25C19.40356 25 25 19.40356 25 12.5C25 5.596441 19.40356 0 12.5 0C5.596441 0 0 5.596441 0 12.5C0 19.40356 5.596441 25 12.5 25M16 6C17.65685 6 19 7.342264 19 8.998786L19 16. 00121C19 17.6574 17.65348 19 16 19C14.34315 19 13 17.65774 13 16.00121L13 8.998786C13 7.342602 14.34652 6 16 6M14 16.00121C14 17.10523 14.89521 18 16 18C17.10263 18 18 17.10369 18 16.00121L18 8. 998786C18 7.894774 17.10479 7 16 7C14.89737 7 14 7.896314 14 8.998786L14 16.00121M8.334739 12.5C8.144151 12.34512 7.578207 11.82732 7.578207 11.82732C6.803066 11.06955 6 10.03477 6 9C6 7 7 6 9 6C11  6 12 7 12 9C12 10.03477 11.19693 11.06955 10.42179 11.82732C10.42179 11.82732 9.855849 12.34512 9.665261 12.5C9.855849 12.65488 10.42179 13.17268 10.42179 13.17268C11.19693 13.93046 12 14.96523 12  16C12 18 11 19 9 19C7 19 6 18 6 16C6 14.96523 6.803066 13.93046 7.578207 13.17268C7.578207 13.17268 8.144151 12.65488 8.334739 12.5M9.034604 12C10.19962 11.05326 11 9.74316 11 9C11 7.552285 10.44771  7 9 7C7.552285 7 7 7.552285 7 9C7 9.74316 7.869587 11.05326 9.034604 12M8.965396 13C7.800378 13.94674 7 15.25684 7 16C7 17.44772 7.552285 18 9 18C10.44771 18 11 17.44772 11 16C11 15.25684 10.13041 13 .94674 8.965396 13M12.5 24C6.148726 24 1 18.85127 1 12.5C1 6.148726 6.148726 1 12.5 1C18.85127 1 24 6.148726 24 12.5C24 18.85127 18.85127 24 12.5 24" 
     android:fillColor="#ffffff" 
     auto:fillColor="#ffffff" /> 
</vector> 

我手动删除了所有auto:xxx标签和结束与

<?xml version="1.0" encoding="utf-8"?> 
<vector 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    tools:ignore="NewApi" 
    android:viewportWidth="25" 
    android:viewportHeight="25" 
    android:width="25dp" 
    android:height="25dp" 
    > 
    <path 
     android:pathData="M12.5 25C19.40356 25 25 19.40356 25 12.5C25 5.596441 19.40356 0 12.5 0C5.596441 0 0 5.596441 0 12.5C0 19.40356 5.596441 25 12.5 25M16 6C17.65685 6 19 7.342264 19 8.998786L19 16.00121C19 17.6574 17.65348 19 16 19C14.34315 19 13 17.65774 13 16.00121L13 8.998786C13 7.342602 14.34652 6 16 6M14 16.00121C14 17.10523 14.89521 18 16 18C17.10263 18 18 17.10369 18 16.00121L18 8.998786C18 7.894774 17.10479 7 16 7C14.89737 7 14 7.896314 14 8.998786L14 16.00121M8.334739 12.5C8.144151 12.34512 7.578207 11.82732 7.578207 11.82732C6.803066 11.06955 6 10.03477 6 9C6 7 7 6 9 6C11 6 12 7 12 9C12 10.03477 11.19693 11.06955 10.42179 11.82732C10.42179 11.82732 9.855849 12.34512 9.665261 12.5C9.855849 12.65488 10.42179 13.17268 10.42179 13.17268C11.19693 13.93046 12 14.96523 12 16C12 18 11 19 9 19C7 19 6 18 6 16C6 14.96523 6.803066 13.93046 7.578207 13.17268C7.578207 13.17268 8.144151 12.65488 8.334739 12.5M9.034604 12C10.19962 11.05326 11 9.74316 11 9C11 7.552285 10.44771 7 9 7C7.552285 7 7 7.552285 7 9C7 9.74316 7.869587 11.05326 9.034604 12M8.965396 13C7.800378 13.94674 7 15.25684 7 16C7 17.44772 7.552285 18 9 18C10.44771 18 11 17.44772 11 16C11 15.25684 10.13041 13.94674 8.965396 13M12.5 24C6.148726 24 1 18.85127 1 12.5C1 6.148726 6.148726 1 12.5 1C18.85127 1 24 6.148726 24 12.5C24 18.85127 18.85127 24 12.5 24" 
     android:fillColor="#ffffff" 
     /> 
</vector> 

这是我一直在寻找。

+1

实际上'android:fillType =“evenOdd”'现在支持几个月:https://issuetracker.google.com/issues/70782765 –