gpt4 book ai didi

android - VectorDrawable 不显示或绘制错误

转载 作者:行者123 更新时间:2023-11-30 00:10:56 26 4
gpt4 key购买 nike

我有 5 个 vectorDrawables,其中 3 个是从 google 给我的 PSD 生成的.

其中两个显示正确(均来自 PSD 生成的矢量),但另外两个在 API 21 上运行时根本不起作用,但在 API 26、27 上运行良好。

enter image description here

没有显示的两个向量看起来像这样

enter image description here

两个 ImageButton 看起来像这样:( full XML file )

  <ImageButton
android:id="@+id/multiplayerButton"
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_marginTop="4dp"
android:background="@drawable/rounded_corners"
android:paddingBottom="2dp"
android:paddingTop="2dp"
android:scaleType="fitCenter"
android:src="@drawable/button_multiplayer_icon"
app:layout_constraintEnd_toEndOf="@id/guideline3"
app:layout_constraintStart_toStartOf="@id/guideline2"
app:layout_constraintTop_toBottomOf="@id/startButton" />

<ImageButton
android:id="@+id/achievementButton"
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_marginStart="2dp"
android:layout_marginTop="4dp"
android:background="@drawable/rounded_corners"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:scaleType="fitCenter"
android:src="@drawable/button_achievements_icon"
app:layout_constraintEnd_toEndOf="@id/multiplayerButton"
app:layout_constraintStart_toEndOf="@id/highscoreButton"
app:layout_constraintTop_toBottomOf="@id/multiplayerButton" />

vector 看起来是这样的

<vector android:height="24dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@color/menu_buttons" android:name="ic multiplayer"
android:pathData="m468.9 41.5 -73.1 15.5 -127.2 139.4 43.1 47.3 141.6 -129.2 15.5 -73.1zm-267.5 228.6 -55.8 61.2 -28.7 -28.7 -28.8 28.7 20 20 -69.5 69.5 51.6 51.6 69.4 -69.5 19.4 19.3 28.7 -28.7 -28.7 -28.7 63 -57.5 -40.7 -37.2zm-158.4 -228.6 15.6 73.1 274.3 250.3 -28.7 28.7 28.8 28.8 19.3 -19.3 69.5 69.5 51.6 -51.6 -69.4 -69.5 20 -20 -28.8 -28.7 -28.7 28.7 -250.3 -274.3 -73.1 -15.5z"/>

功能区vector xml 文件如下所示

<vector android:height="24dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@color/menu_buttons" android:name="ic achievements"
android:pathData="m256.3 343.9 47.2 21.9 23 -34.2 55.3 104 -69.8 68.3 -55.7 -160zm-0.7 0 -47.2 21.9 -22.9 -34.2 -55.3 104 69.8 68.3 55.7 -160zm0.3 -296.5 43.1 -20 27.4 38.9 47.3 4.2 4.2 47.4 38.9 27.3 -20 43.1 20 43.1 -38.9 27.4 -4.2 47.3 -47.3 4.2 -27.4 38.9 -43.1 -20 -43.1 20 -27.4 -38.9 -47.3 -4.2 -4.2 -47.3 -38.9 -27.4 20 -43.1 -20 -43.1 38.9 -27.3 4.2 -47.4 47.3 -4.2 27.4 -38.9 43.1 20zm0.2 48.5c-50.8 0 -92.1 41.2 -92.1 92c0 50.9 41.2 92.1 92.1 92.1c50.8 0 92 -41.2 92 -92.1c0 -50.8 -41.2 -92 -92 -92z"/>

其中变量menu_buttons定义为#FFC107,在colors.xml

最佳答案

VectorDrawable在 API 级别 21 中添加。

Support Library 23.2 or higher provides full support to Vector Drawables and Animated Vector Drawables on devices running Android 5.0 (API level 21) or lower.

你应该使用

 app:srcCompat="@drawable/your_vector_image"

您需要将 vectorDrawables.useSupportLibrary = true 添加到您的 build.gradle 文件中:

// Gradle Plugin 2.0+  
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}

仅供引用

app:srcCompat attribute to reference vector drawables as well as any other drawable available to android:src.

关于android - VectorDrawable 不显示或绘制错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48148616/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com