简体   繁体   English

Android:矢量资产失真

[英]Android: vector asset distortion

I created a vector asset in Android Studio that i can see correctly but once i launch my app it gets distorted. 我在Android Studio中创建了一个矢量资产,可以正确看到它,但是一旦启动我的应用程序,它就会变形。

Original Vector Asset 原始向量资产

Distorted In App 应用程式失真

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="45dp"
    android:height="79dp"
    android:viewportWidth="45.9"
    android:viewportHeight="79.2">
<path
    android:fillColor="#FF000000"
    android:pathData="M22.9,1.5C42.1,1.6 41.7,3 41.7,3s1.2,-1.1 -0.7,-1.9S28.7,0 22.9,0S6.7,0.4 4.8,1.1S4.1,3 4.1,3S3.7,1.6 22.9,1.5"/>
<path
    android:fillColor="#FF000000"
    android:pathData="M22.9,3c19.2,0.1 18.5,1.4 18.5,1.4S41,4.9 42.1,7c1.1,2.2 3.4,6.7 3.4,6.7s-7.6,-1 -22.6,-0.9c-15.2,-0.1 -15,-0.1 -22.6,0.9c0,0 2.4,-4.5 3.4,-6.7c0.2,-0.4 1.6,-1.7 0.7,-2.6C4.4,4.4 3.7,3.1 22.9,3"/>
<path
    android:fillColor="#FF000000"
    android:pathData="M22.9,71.4c22,0 22.9,-1.7 22.9,-1.7l0.1,-54.4c0,0 -7.9,-1.2 -22.9,-1.1C7.9,14.1 0,15.3 0,15.3l0.1,54.4C0.1,69.7 0.9,71.4 22.9,71.4"/>
<path
    android:fillColor="#FF000000"
    android:pathData="M22.9,75.2C10.7,75.2 4.6,74 4.6,74c-4.2,-1.1 -4.5,-2.6 -4.5,-2.6S0.9,73 22.9,73s22.9,-1.7 22.9,-1.7s-0.3,1.5 -4.5,2.6C41.3,74 35.2,75.2 22.9,75.2"/>
<path
    android:fillColor="#FF000000"
    android:pathData="M22.9,79.2c-16.5,0 -16.4,-1.3 -16.4,-1.3l-1.3,-2.1c0,0 5.5,1.3 17.7,1.3s17.7,-1.3 17.7,-1.3l-1.3,2.1C39.3,77.9 39.4,79.2 22.9,79.2"/>

I'm using the drawable as a menu item icon, all icons in the menu are good except for the ic_menu_item which is distorted. 我使用drawable作为菜单项图标,菜单中的所有图标都不错,除了ic_menu_item变形了。

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_weapon"
            android:icon="@drawable/ic_menu_weapon"
            android:title="Weapons" />
        <item
            android:id="@+id/nav_item"
            android:icon="@drawable/ic_menu_item"
            android:title="Items" />
    </group>
</menu>

How are you using the drawable inside of a layout? 您如何在布局内部使用可绘制对象? I've had problems with using "wrap_content" when using non-square vectors. 使用非正方形向量时,我在使用“ wrap_content”时遇到了问题。 Can you try setting the view dimensions in the layout to match one of the dimensions (width or height), then using "wrap_content" with the other? 您可以尝试在布局中设置视图尺寸以匹配其中一个尺寸(宽度或高度),然后将“ wrap_content”与另一个尺寸一起使用吗?

Example: 例:

<ImageView
    android:layout_width="45dp"
    android:layout_height="wrap_content"
    android:src="@drawable/drawable_src"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM