RotateDrawable以编程方式在android中

前端之家收集整理的这篇文章主要介绍了RotateDrawable以编程方式在android中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我怎么能以编程方式给出Fegrees,toDegrees和 android:color =“#000000”?
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
  3. <item >
  4.  
  5.  
  6. <rotate
  7. android:fromDegrees="45"
  8. android:toDegrees="45"
  9. android:pivotX="-40%"
  10. android:pivotY="87%" >
  11.  
  12. <shape
  13. android:shape="rectangle" >
  14. <stroke android:color="@android:color/transparent" android:width="10dp"/>
  15. <solid
  16. android:color="#000000" />
  17. </shape>
  18.  
  19. </rotate>
  20. </item>
  21. </layer-list>

我在视图的背景中使用此xml.

我必须以编程方式创建三角形.所以需要以编程方式创建RotationDrawable.

解决方法

这是一个很好的解决方案,为imageView放置一个旋转的drawable:
  1. RotateAnimation anim = new RotateAnimation(0.0f,360.0f,Animation.RELATIVE_TO_SELF,.5f,.5f);
  2. anim.setInterpolator(new LinearInterpolator());
  3. anim.setRepeatCount(Animation.INFINITE);
  4. anim.setDuration(3000);
  5. iv.setAnimation(anim);
  6. iv.startAnimation(anim);

猜你在找的Android相关文章