Проблема со шкалой SVG в android - PullRequest
0 голосов
/ 28 апреля 2020

Я пытаюсь добавить SVG в свой макет, но проблема в боковом заполнении и верхнем заполнении. Я хочу, чтобы моя svg начиналась сверху без каких-либо отступов, а также с левой и боковой сторон.

Ниже приведен код моего макета XML, похожий на

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/overview_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:contentDescription="image"
        android:scaleType="centerInside"
        android:src="@drawable/path" />
</LinearLayout>

И мой Код SVG

<vector android:height="160dp"
    android:viewportHeight="433.154"
    android:viewportWidth="1260"
    android:width="500dp"
    xmlns:android="http://schemas.android.com/apk/res/android">


  <path android:fillColor="#803ef6"
        android:pathData="M90,149.52c22.6,-54.47 52.2,-81.02 85.31,-68.8s397.97,176.79 648.32,226.77c87.62,17.49 156.34,-7.58 208.53,-47.46C1129.43,185.68 1170,60 1170,60L90,60Z"/>
</vector>

Я испробовал все опции в android: scaleType, но не смог добиться желаемого.

image

Ниже дизайн - это то, чего я хочу достичь.

Image2

SVG сделан в Adobe XD.

1 Ответ

0 голосов
/ 28 апреля 2020

Внесите следующие изменения:

<RelativeLayout
    android:id="@+id/lin"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/overview_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:contentDescription="image"
        android:scaleX="1.20"
        android:scaleY="1.40"
        android:background="@drawable/ic_launcher_background" />

    </RelativeLayout>


</RelativeLayout>

Векторный файл SVG:

<vector android:height="160dp"
    android:viewportHeight="433.154"
    android:viewportWidth="1275"
    android:width="500dp"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <path android:fillColor="#803ef6"
        android:pathData="M90,149.52c22.6,-54.47 52.2,-81.02 85.31,-68.8s397.97,176.79 648.32,226.77c87.62,17.49 156.34,-7.58 208.53,-47.46C1129.43,185.68 1170,60 1170,60L90,60Z"/>
</vector>

enter image description here

...