安卓RotateDrawable : Doesn't correctly work for Vector Drawables

标签 android svg vector rotation android-drawable

RotateDrawble 中使用 Vector Drawable 时观察到一个奇妙的问题,每个 完整周期两次(0° 到 360°/级别:0 → 10000)!第一个大约 90°(level: 2500),另一个大约 270°(level: 7500)。看下面的测试:


我的RotateDrawable(文件名:rotatable_info.xml):

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360"
    android:drawable="@drawable/ic_info_black_24dp" >
</rotate>

我的布局设计:

<LinearLayout android:orientation="vertical"
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <ImageView style="@style/style" android:id="@+id/ImageView00" />
    <ImageView style="@style/style" android:id="@+id/ImageView01" />
    <ImageView style="@style/style" android:id="@+id/ImageView02" />
    ...
    <ImageView style="@style/style" android:id="@+id/ImageView19" />
</LinearLayout>

引用样式:

<style name="style">
    <item name="android:layout_width">32dp</item>
    <item name="android:layout_height">32dp</item>
    <item name="android:src">@drawable/rotatable_info</item>
</style>

我的代码:

int n = -550;
((RotateDrawable) this.<ImageView>findViewById(R.id.ImageView00).getDrawable()).mutate().setLevel(n+=550);
((RotateDrawable) this.<ImageView>findViewById(R.id.ImageView01).getDrawable()).mutate().setLevel(n+=550);
...
((RotateDrawable) this.<ImageView>findViewById(R.id.ImageView18).getDrawable()).mutate().setLevel(n+=550);
((RotateDrawable) this.<ImageView>findViewById(R.id.ImageView19).getDrawable()).mutate().setLevel(n+=550);

(.mutate() 需要为每个 ImageView 独立执行旋转。它对主要问题没有影响。)

我的结果(!?!?):

Wonderful RotateDrawable for Vectors


ic_info_black_24dp.xml:(由Android Studio中的Vector Asset Studio生成...我还测试了一些其他SVG。光栅drawables没有问题。)

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2L11,7h2v2z"/>
</vector>

最佳答案

似乎是一个错误。 vectorDrawables.useSupportLibrary = true 解决了这个问题。

有关详细信息,请参阅下面的“矢量绘图向后兼容解决方案”部分:

https://developer.android.com/guide/topics/graphics/vector-drawable-resources

关于安卓RotateDrawable : Doesn't correctly work for Vector Drawables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50458751/

相关文章:

c++ - 关于行列式计算的一段代码问题

java - 动态列表从未加载 - 使用 parse.com

java - Android 日历 View 更改文本颜色

android - 自定义 ArrayAdapter 过滤器没有结果

android - SDK platform-tools 版本(24.0.4)太旧,无法检查使用API​​ 25编译的API;请更新

javascript - 在 Raphaël JS 生成的图像中查找给定元素的坐标

javascript - d3.scale.linear() 与 d3.scaleLinear()

c++ - 如何保留指向插入集合然后插入 vector 的对象的指针?

vector - 是否可以从函数返回两个向量?

php - 使背景图像 SVG 像内联元素一样工作