android - Android RotateDrawable:不适用于矢量可绘制对象
问题描述
在每个完整周期(0° 到 360° / )中使用Vector Drawable时观察到一个 WONDERFUL 问题!首先大约90° ( )和另一个大约270° ( )。看下面的测试:RotateDrawble
level: 0 → 10000
level: 2500
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
。它对主要问题没有影响。)
我的结果(!?!?):
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
推荐阅读
- json - SharePoint 自动更新计算列
- r - 循环程序与其他程序的命令
- c++ - 如何用 Arduino 制作伺服按钮?
- vue.js - vuejs 出现错误“[vuex] 未知操作类型:”
- wordpress - WooCommerce REST API:网关不支持管理员更改订阅的付款方式
- php - 通过ajax使用复选框发送多个数据
- c# - 尝试忽略 Winforms 中的空文本框以过滤 sql 搜索查询
- node.js - Repl.it 监听 EADDRINUSE: 地址已经在使用 :::3001
- javascript - 遍历字典 - JavaScript
- apache-storm - 我们的拓扑在 Storm 2.2.0 中的运行速度明显比在 1.2.0 中慢