浮动操作按钮未显示矢量资产 [英] Floating action button not showing vector asset

查看:77
本文介绍了浮动操作按钮未显示矢量资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将矢量资产设置到fab中.但是结果是这样的: 如您所见,矢量在那里,但是向下和向左.这是布局

I'm trying to setup a vector asset into a fab. But the result is like this: As you can see the vector is there but way down and to the left. here is the layout

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBg"
    tools:context=".ui.main.fragments.HomeFragment">


    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab_new_sale"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="16dp"
        app:backgroundTint="@color/colorAccent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:srcCompat="@drawable/ic_cart_plus"
        android:scaleType="center"/>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv_home_cards"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:foregroundGravity="center_vertical|center"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>

这里是向量:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="200dp"
    android:height="200dp"
    android:viewportWidth="200"
    android:viewportHeight="200">
    <path
        android:fillColor="#FF000000"
        android:pathData="M165.1,119.28L75,119.28l2,9.84h82.48a7.37,7.37 0,0 1,7.19 9l-1.7,7.46a17.2,17.2 0,1 1,-19.54 3.19L81,148.77a17.21,17.21 0,1 1,-20.6 -2.63L38.85,40.62L17.38,40.62A7.38,7.38 0,0 1,10 33.24L10,28.33A7.37,7.37 0,0 1,17.38 21h31.5a7.38,7.38 0,0 1,7.23 5.9l2.81,13.77h120.7a7.37,7.37 0,0 1,7.19 9l-14.52,63.91A7.38,7.38 0,0 1,165.1 119.28ZM135.38,72.58L120.63,72.58L120.63,60.28a4.92,4.92 0,0 0,-4.92 -4.91h-4.92a4.91,4.91 0,0 0,-4.91 4.91v12.3L91.13,72.58a4.91,4.91 0,0 0,-4.92 4.91v4.92a4.92,4.92 0,0 0,4.92 4.92h14.75L105.88,99.62a4.91,4.91 0,0 0,4.91 4.91h4.92a4.92,4.92 0,0 0,4.92 -4.91L120.63,87.33h14.75a4.92,4.92 0,0 0,4.91 -4.92L140.29,77.49A4.91,4.91 0,0 0,135.38 72.58Z" />
</vector>

对于此问题的任何帮助,我们将不胜感激

I will appreciate any help with this issue

推荐答案

设置

android {
   defaultConfig {
     vectorDrawables.useSupportLibrary = true
    }
 }

在您的build.gradle

这篇关于浮动操作按钮未显示矢量资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆