android-在LayerDrawable中旋转单个RotateDrawable

android-在LayerDrawable中旋转单个RotateDrawable,第1张

概述我正在构建一个其中包含某种指南针的应用程序,并且我想使用LayerDrawable绘制和设置指南针动画.LayerDrawable由用于罗盘背景的静态背景图像和用于旋转零件的RotateDrawable组成.这是我的可绘制资源的XML代码:Compass_text.xml:<?xmlversion="1.0"encoding="utf-8"?><rotatex

我正在构建一个其中包含某种指南针的应用程序,并且我想使用LayerDrawable绘制和设置指南针动画. LayerDrawable由用于罗盘背景的静态背景图像和用于旋转零件的RotateDrawable组成.这是我的可绘制资源的XML代码:

Compass_text.xml:

<?xml version="1.0" enCoding="utf-8"?><rotate xmlns:androID="http://schemas.androID.com/apk/res/androID"     androID:drawable="@drawable/compasstext"    androID:fromdegrees="0"    androID:todegrees="360"    androID:pivotX="50%"    androID:pivotY="50%" />

guIDe_layers.xml:

<?xml version="1.0" enCoding="utf-8"?><@R_701_3419@ xmlns:androID="http://schemas.androID.com/apk/res/androID" >    <item androID:drawable="@drawable/compassbackground" />    <item androID:drawable="@drawable/compass_text" /></@R_701_3419@>

LayerDrawable的显示效果很好,但是如何旋转呢?这是我尝试的代码:

compasstext = (RotateDrawable)getResources().getDrawable(R.drawable.compass_text);compasstext.setLevel(5000);

这什么也没做.我究竟做错了什么?

解决方法:

您需要确保在设置级别之前获取了已膨胀的特定Drawable,而不是资源中的通用Drawable对象.尝试这个:

ImageVIEw iv = (ImageVIEw) findVIEwByID(R.ID.xxx); ////where xxx is the ID of your ImageVIEw (or whatever other vIEw you are using) in your xml layout fileLayerDrawable lv = (LayerDrawable) iv.getDrawable();compasstext = (RotateDrawable) lv.getDrawable(1); //1 should be the index of your compasstext since it is the second element in your xml filecompasstext.setLevel(5000);
总结

以上是内存溢出为你收集整理的android-在LayerDrawable中旋转单个RotateDrawable全部内容,希望文章能够帮你解决android-在LayerDrawable中旋转单个RotateDrawable所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1072385.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存