我创建了一个矢量可绘制对象,并将其显示在布局的ImageView
中。但是,图像未正确显示,如所附的屏幕截图所示。
这里是Vector Drawable的xml。
<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中正确显示的矢量绘制
矢量绘图在应用程序的布局中未正确显示。
关于我在做什么错的任何想法?
实际上,Android中的Vector图像可以看作图像,但是有一种适当的方法可以在xml内部调用vector drawable,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>