Неверно отображаемый вектор в приложении Android - PullRequest
0 голосов
/ 03 октября 2019

Я создал векторную графику, которую я отображаю в ImageView в макете. Тем не менее, изображение отображается неправильно, как показано на скриншоте.

Вот XML для Vector Drawable.

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aapt="http://schemas.android.com/aapt"
    android:width="78dp"
    android:height="120dp"
    android:viewportWidth="78"
    android:viewportHeight="120">
  <path
      android:pathData="M8,111a31,9 0,1 0,62 0a31,9 0,1 0,-62 0z"
      android:fillColor="#000"
      android:fillAlpha=".08"
      android:fillType="evenOdd"/>
  <path
      android:pathData="M39,109c24.667,-33.044 37,-56.377 37,-70C76,18.565 59.435,2 39,2S2,18.565 2,39c0,13.623 12.333,36.956 37,70zM39,54c7.732,0 14,-6.268 14,-14s-6.268,-14 -14,-14 -14,6.268 -14,14 6.268,14 14,14z"
      android:strokeLineJoin="round"
      android:strokeWidth="4"
      android:strokeColor="#50BEFF"
      android:fillType="evenOdd">
    <aapt:attr name="android:fillColor">
      <gradient 
          android:startY="39.25312"
          android:startX="39"
          android:endY="40.31242"
          android:endX="39"
          android:type="linear">
        <item android:offset="0" android:color="#FF50BEFF"/>
        <item android:offset="1" android:color="#FF4BAFFF"/>
      </gradient>
    </aapt:attr>
  </path>
</vector>

И XML для макета

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drive_case_list_empty_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:paddingBottom="16dp"
    android:visibility="visible">

    <ImageView
        android:id="@+id/drive_case_list_content_marker_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        app:srcCompat="@drawable/ic_location" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/drive_case_list_content_marker_image"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="24dp"
        android:text="@string/drive_case_list_empty_title_text"
        android:textSize="14sp"
        android:textColor="@color/black87"
        android:textAlignment="center"/>

</RelativeLayout>

Вектор рисования корректно отображается в Android Studio

enter image description here

Вектор рисования некорректно отображается в макете приложения.

enter image description here

Есть идеи, что я делаю не так?

1 Ответ

0 голосов
/ 03 октября 2019

На самом деле векторные изображения в android можно просматривать как изображения, но есть правильный способ назвать вектор, который можно нарисовать внутри xml, Vector рассматривается как значок или элемент в android studio, поэтому просто попробуйте сделать это таким образом.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drive_case_list_empty_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:paddingBottom="16dp"
android:visibility="visible">

<item
    android:id="@+id/drive_case_list_content_marker_image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    app:srcCompat="@drawable/ic_location" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/drive_case_list_content_marker_image"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="24dp"
    android:text="@string/drive_case_list_empty_title_text"
    android:textSize="14sp"
    android:textColor="@color/black87"
    android:textAlignment="center"/>

</RelativeLayout>
...